Reputation: 67355
One of my websites needs to call the API of another one of my websites.
My plan to display a "wait" popup while the page makes an AJAX call to direct the server-side code to make the API call.
But there is the potential that it could take a little while. I'm looking for advice on how to prevent the AJAX call from timing out.
When I Google this issue, most of the articles I've read suggest sending just a few items at a time. But in my case, it's all done in one rather substantial call.
What other options are there to prevent the page from timing out?
Upvotes: 0
Views: 1639
Reputation: 1721
Based on the comments, I got that your need to keep server pinging in some particular time interval.
setInterval(function() {
$.ajax({url: "ping.txt",
success: function(result){
//Nothing to do, or your can check the content of your ping.txt
},
error : function(){
//Code to show your wait popup
}
});
}, 60000);
This will keep your connection alive i.e. you would know if you are connected to the server.
You need to put ping.txt on your server accordingly.
Upvotes: 0
Reputation: 915
If you cant implement loading in packets etc, then timeout is probably your best option.
$.ajax({
dataType: "json",
url: uriTrackers, // Your URL here.
//data: data, //we are not sending data, this is a different data to the one below
timeout: 10000 //10 second timeout or maybe 30 secs if debugging
})
.done(function (data) {
// Anything you want to do on success here.
})
.fail(function (jqXHR, textStatus, err) {
$('#TrackerInfo').text('Error: ' + err + uriTrackers);
});
Upvotes: 2