I am wondering what is the best way to handle timeouts using jQuery.ajax () . This is my solution at the moment: if a timeout occurs, the page will reload, and the script will get another chance to load data within the specified timeframe.
Problem : if "get_json.php" (example below) is really unavailable, it will become an infinite reload cycle. Possible solution: add a counter and cancel after rebooting $ x.
Question 1 : What is the best way to deal with a timeout error?
Question 2 : What is your recommended timeout for a timeout and why?
The code
$.ajax({ type: "POST", url: "get_json.php", timeout: 500, dataType: "json", success: function(json) { alert("JSON loaded: " + json); }, error: function(request, status, err) { if (status == "timeout") {
Thanks in advance!
Mr. B.
source share