2016-08-19 118 views
0

我尝试使用下面的情景测试错误回调触发错误回调jQuery的AJAX:无法使用PHP

  1. 我的网址更改:“telemetry.php”到URL:“asdasfjgafas.php”
  2. <?php header("HTTP/1.1 404 Not Found"); exit() >内telemetry.php

但是,我没有得到警报()错误回调,甚至尝试1和2分别后!

我使用jQuery的.js内容制作AJAX请求:

$.ajax({ 

    url  : "telemetry.php", 
    data : ({ 
        DshBrdName : strFullDashBoardName, 
        DshBrdID : currentDashboard, 
        r   : Math.random() 
       }), 
    success : function(data, textStatus, jQxhr){ 
        alert(textStatus); 
       }, 
    error : function(jqXHR, textStatus, errorThrown){ 
        alert(textStatus); 
        alert(errorThrown); 
       }, 
    type : "POST" 
}); 

P.S:我能够获得成功的警报时,我有合法的URL和有效的PHP代码!

回答

1

我可以在你的错误块看到一个错字:

function(jqXHR, textStatus, errorThrown){ 
       alert(testStatus); // should be textStatus? 
       alert(errorThrown); 
      }, 

编辑

从JS的角度来看,似乎一切都ok了,下面你片断(我更换了未定义的变量与字符串)警报错误(因为这个PHP脚本显然没有找到)。你可能想提供有关在服务器端发生的事情更详细...

$.ajax({ 
 

 
    url  : "telemetry.php", 
 
    data : ({ 
 
        DshBrdName : 'strFullDashBoardName', 
 
        DshBrdID : 'currentDashboard', 
 
        r   : Math.random() 
 
       }), 
 
    success : function(data, textStatus, jQxhr){ 
 
        alert(textStatus); 
 
       }, 
 
    error : function(jqXHR, textStatus, errorThrown){ 
 
        alert(textStatus); 
 
        alert(errorThrown); 
 
       }, 
 
    type : "POST" 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

是你可能在控制台错误,指出'testStatus'是不确定的。 – jcubic

+0

对不起家伙..我手动输入这些警报在stackoverflow页面,而不是从我的PHP文件复制...这不是一个错字问题!在真正的代码中,确实是alert(textStatus) –

+0

在这里运行你的脚本会得到警报,所以问题可能不会出现在javascript中。 – kennasoft