How long can the browser wait before an error is shown before server answers for request? Can this time be unlimited?
As other answers mentioned you can use ajaxStop() to wait until all ajax request are completed. If you want do it for an specific ajax() request the best you can do is use complete() method inside the certain ajax request: $.
$. ajax({ url: "page. php", data: stuff, success: function(response){ console. log("success"); } });
If this is a busy server or overloaded server, then it could be that your app is swapped out of memory or the cache is empty and it takes a longer time to get your app up and running and ready to start processing the response.
Session timeout has been a very common feature in Ajax-based web applications. In responsive interface, the programmer needs to delay the ajax request to achieve some task before the response. This can be achieved by using jQuery setTimeout() function.
If you are using a jQuery $.ajax call you can set the timeout property to control the amount of time before a request returns with a timeout status. The timeout is set in milliseconds, so just set it to a very high value. You can also set it to 0 for "unlimited" but in my opinion you should just set a high value instead.
Note: unlimited is actually the default but most browsers have default timeouts that will be hit.
When an ajax call is returned due to timeout it will return with an error status of "timeout" that you can handle with a separate case if needed.
So if you want to set a timeout of 3 seconds, and handle the timeout here is an example:
$.ajax({ url: "/your_ajax_method/", type: "GET", dataType: "json", timeout: 3000, //Set your timeout value in milliseconds or 0 for unlimited success: function(response) { alert(response); }, error: function(jqXHR, textStatus, errorThrown) { if(textStatus==="timeout") { alert("Call has timed out"); //Handle the timeout } else { alert("Another error was returned"); //Handle other error type } } });
Yes and no. Yes the server can do it or be configured to do so, no the browsers (i dont know about version/distributor specifics) may have timeouts enabled.
There are 2 solutions though for achieving/emulating this over HTTP:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With