微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

发送php响应给ajax

好的,我有一个 PHP脚本,结尾如此:
if ($success)
{
    $result = array('success' => true);
}
else
{
    $result = array('success' => false,'message' => 'Something happened');
    header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error',true,500);
}
  echo json_encode($result);

还有一些jquery,我计划在我的脚本运行时提醒我.

jQuery(document).ready(function() {

    $.ajax({
        url: './contactengine.PHP',type: 'GET',dataType: 'JSON',success: function(response) {
                        alert("GOOD");
                },error: function() {
                        alert("BAD");
                }
    });

});

编辑来源

<?PHP 
        if ($success){
             $result = array("status" => "1");

             echo json_encode($result);
            }
            else{
              print "<Meta http-equiv=\"refresh\" content=\"0;URL=/404.html\">";
            }    
        ?>
        <script>
        jQuery(document).ready(function() {

          $.ajax({
                           type: 'GET',url:  'Thatscriptsomething.PHP',cache: 'false',dataType: 'json',success: function(response) {
                               if(response.status == "1") {
                                    alert("we having a working script");
                               } else {
                                    alert("Oops,script is a no go");
                               }
                            }
                        });
        });
        </script>

原文地址:https://www.jb51.cc/php/130270.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐