2010-08-22 59 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