检查jQuery';由于连接丢失,s$.post()失败

检查jQuery';由于连接丢失,s$.post()失败,post,jquery,Post,Jquery,我在脚本中,在$(document).ready(function(){ jQuery说: 如果带有jQuery.post()的请求返回错误代码,则除非脚本还调用了global.ajaxError()方法,否则它将以静默方式失败 我试着添加这个作为第一个测试 $(document).ajaxError(function(e, xhr, settings, exception) { alert('error in: ' + settings.url + ' \\n'+'error:\\n' + e

我在脚本中,在$(document).ready(function(){

jQuery说:

如果带有jQuery.post()的请求返回错误代码,则除非脚本还调用了global.ajaxError()方法,否则它将以静默方式失败

我试着添加这个作为第一个测试

$(document).ajaxError(function(e, xhr, settings, exception) {
alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
});

但它什么也没做。有人能帮忙吗?如果internet连接断开,我只需要弹出一个警报。我也尝试过使用window.navigator.onLine进行此操作,但Safari不支持它。您是否尝试过不将其绑定到文档

$('.log').ajaxError(function(e, xhr, settings, exception) {
   alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
});

呜呜,看起来我设法摆脱了我与原始帖子的联系——我写了这篇帖子

无论如何,为了澄清,我的代码是:

  $(document).ready(function(){ 

$(this).ajaxError(function(e, xhr, settings, exception) {
    alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
});

$.post("dostuf.php", { action: "thething"  });
没有抛出错误。

不确定是否在.post()上;但是在.ajax()的api中有一个可以传递给对象的错误函数

$.ajax({
    type:"post",
    url:"http://yourwebservice.com/get_data",
    error:function(XMLHttpRequest, textStatus, errorThrown) { 
        //do stuff 
        alert('fail whale');
    },
    success:function(data) {
        alert('it worked!');
    }        
});


顺便说一句,欢迎使用stackoverflow!

它的工作方式应该是相同的,所有绑定到它的元素都会触发事件…jQuery会对
$对象进行爬网。cache
对象检查要触发它的对象。您的用户名和用户ID似乎已更改。奇怪。@Keyo,@BoltClock-他是用另一个OpenID登录的