我正在尝试用jQuery 1.4.2捕获Ajax超时错误,但没有找到工作的教程。在Firebug中,当超时错误触发时。我看到uncaught exception: [object Object]
。请帮我处理Ajax超时。这是我的JS代码:
$.ajax({
type:"POST",
url:"/data/add/",
data:
{
"date":$("input#date").val();
},
dataType:"json",
timeout:2000,
success: function(response) {
},
error: function () {
alert('Server error');
}
});
答案 0 :(得分: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');
}
});
答案 1 :(得分:1)
又出现了问题,我用Google搜索了这个错误的http://dev.jquery.com/ticket/6173!这是秒杀:
success: function(response, textStatus, xhr) {
if (!xhr.status) {
alert("ERROR!!!!");
}
else {
......... }