2010-08-22 62 views
3

我试图用jQuery 1.4.2来捕捉Ajax超时错误,但没有找到任何教程工作。在Firebug中,超时错误触发。我看到uncaught exception: [object Object]。请帮我处理Ajax超时。这里是我的JS代码:jQuery句柄Ajax超时?

$.ajax({ 
    type:"POST", 
    url:"/data/add/", 
    data: 
    { 
    "date":$("input#date").val(); 
    }, 
    dataType:"json", 
    timeout:2000, 
    success: function(response) { 
    }, 
    error: function() { 
     alert('Server error'); 
    } 
}); 
+0

您的数据选择一个错误的分号。请参阅下面的答案。 – 2010-08-22 03:35:03

回答

1

再次出现问题,我用Google搜索了这个错误http://dev.jquery.com/ticket/6173!这里是秒杀:

success: function(response, textStatus, xhr) { 
    if (!xhr.status) { 
     alert("ERROR!!!!"); 
    } 
    else { 

......... }

4

我测试了这一点,如果你从你的$("input#date").val()语句删除;,它应该工作。

$.ajax({ 
    type:"POST", 
    url:"/data/add/", 
    data: 
    { 
    "date":$("input#date").val() 
    }, 
    dataType:"json", 
    timeout:2000, 
    success: function(response) { 
    }, 
    error: function() { 
     alert('Server error'); 
    } 
}); 
+2

+1 - 好。 – 2010-08-22 03:42:05