views:

62

answers:

2

Hi,

I'm trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Firebug, when timeout error fires. I see uncaught exception: [object Object]. Please help me handle Ajax timeout. Here's my JS code:

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

I tested this out, and if you remove the ; from your $("input#date").val() statement, it should work.

$.ajax({
    type:"POST",
    url:"/data/add/",
    data:
    {
    "date":$("input#date").val()
    },
    dataType:"json",
    timeout:2000,
    success: function(response) {
    },
    error: function () {
        alert('Server error');
    }
});
David Hoerster
+1 - Good catch.
Gert G
A: 

something went wrong again, and i got googled this f***g bug http://dev.jquery.com/ticket/6173 ! here is the spike:

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

......... }

teMkaa