Does jQuery handle Ajax timeout?

I am trying to catch an Ajax timeout error using jQuery 1.4.2, but not a single tutorial that I found works. In Firebug, when a timeout error occurs. I see uncaught exception: [object Object]. Please help me deal with the Ajax timeout. Here is 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');
    }
});
+3
source share
2 answers

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

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

.........}

+1
source

I tested this, and if you remove ;from your statement $("input#date").val(), 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');
    }
});
+4
source

Source: https://habr.com/ru/post/1760938/


All Articles