Set timeout for ajax (jQuery)

Please read the $.ajax documentation, this is a covered topic.

    url: "test.html",
    error: function(){
        // will fire when timeout is reached
    success: function(){
        //do something
    timeout: 3000 // sets timeout to 3 seconds

You can get see what type of error was thrown by accessing the textStatus parameter of the error: function(jqXHR, textStatus, errorThrown) option. The options are “timeout”, “error”, “abort”, and “parsererror”.

Leave a Comment