byJeevan byJeevan - 6 months ago 46
Javascript Question

Timeout not working in ajax post request

I am not able to make ajax error callback function of after 3 seconds. I tried with timeout, but it will not switch to error callback after specified time! I am not able to get the alert

Got timeout

When I referred similar questions in this site with similar problems it didn't helped out. They all use ajax GET type. I am using jquery 1.10.1 library.

script :

type: 'POST',
timeout: 3000,
url : "http://mydomain/Services.asmx/Best_Scores",
dataType: "text",
data: "strJsonRequest="+scoredata,
success: function (data) { // Success code ...
error: function (data, textStatus, errorThrown) {
if(textStatus == "timeout") {
alert("Got timeout");


Any solution ?


Fix :

Change async : false to async: true

Reason :

A synchronous AJAX call blocks until the request has been finished. Implementing a timeout is not possible for technical reasons, because the AJAX call would have to be executed later.

If an AJAX call is executed later, the function somehow has to implement a blocking feature, to stop the code from running further after the AJAX call, and execute it again after a timeout - not possible.