加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

发送php响应给ajax

发布时间:2020-05-31 00:37:22 所属栏目:PHP 来源:互联网
导读:好的,我有一个 PHP脚本,结尾如此: if ($success){ $result = array(success = true);}else{ $result = array(success = false, message = Something happened); header($_SERVER[SERVER_PROTOCOL]

好的,我有一个 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>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读