jQuery ajax中的错误没有报告

时间:2011-08-30 12:26:45

标签: jquery ajax firefox handler

我在使用jQuery ajax成功处理程序时遇到了困难。成功处理程序中发生的任何javascript运行时错误似乎都没有报告(Firefox错误控制台中没有出现错误)。并尝试调试没有错误通知让我发疯。有人可以看看下面我的代码的简化版本,让我知道我是否正在做一些可能导致问题的愚蠢。

如果没有,如果有人可以在Firefox中对此进行测试并确认(或不确认)没有出现错误消息,而且不仅仅是我发疯(或者我的Firefox安装有什么问题)。我还把代码放在网上 - 所以你只需点击下面的代码来测试它......

http://www.alisonstrachan.co.uk/tests/ajax2/ajax_test2.html

ajax_test2.html

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    //alert(missingVariable1);           //uncomment -> get error reported (as expected)

    $.ajax({
        url: "ajax_test2_process.php",
        data: {send: "hello"},
        async: false,
        success: function(data){
            $("#results").append(data);
            alert(missingVariable2);     //no error reported (there should be surely?)
            $("#results").append(" finished ");
            }
        });
});

</script>
</head>
<body>
<div id="results"></div>
</body>
</html>

ajax_test2_process.php

<?php
    echo "received: " . $_REQUEST['send'];
?>

4 个答案:

答案 0 :(得分:1)

这可能是由于Adblock Plus或类似的扩展程序(请检查您已安装的扩展程序),请参阅bug 653533

答案 1 :(得分:1)

我的猜测是由于jQuery wrapping the callback in a try...catch而无声地失败。

所以,简单地说,在回调函数中找到的任何错误或错误代码都会默默地失败(并且冒泡到我已经概述的try ... catch)然后停止处理它的位置。

答案 2 :(得分:0)

查看Ajax函数的其他回调函数(http://api.jquery.com/jQuery.ajax/) - 您可能需要查看error以及{{1 Firebug对调查ajax相关问题也非常有用 - 你可以看到ajax通信的帖子和响应。

如果您想使用statusCode

登录firebug控制台

答案 3 :(得分:0)

您也可以尝试将ajax包装在jquery docs建议的对象中

var jqxhr = $.ajax({ url: "example.php" })
    .success(function() { alert("success"); })
    .error(function() { alert("error"); })
    .complete(function() { alert("complete"); });