Reputation: 13448
I am currently redirecting to a main page on success , based on success i want to make the page wait for 30 or 50 sec before the redirect happens and I want to check while waiting if a 500 Internal Error message has occurred .
$(function() {
$("#save").click(function() {
$.ajax({
type: "POST",
url: "cng.json",
data: json_data,
contentType : 'application/json',
success: function(data, textStatus, xhr) {
console.log(arguments);
console.log(xhr.status);
alert("Your changes are being submitted: "+ textStatus +" : "+ xhr.status);
//modal window message
$('<div id="loading">Loading...</div>').insertBefore('#myform');
// add code here to wait for 30 sec before redirecting and check for 500 error code
location.reload(true);
},
error:function(jqXHR, textStatus, errorThrown) {
alert( jqXHR.responseText+" - " +errorThrown + " : " +jqXHR.status);
}
});
});
});
Upvotes: 0
Views: 359
Reputation: 664579
Just use a timeout?
setTimeout(function() {
location.reload(true);
}, 30000);
Btw, 30sec is very long.
Upvotes: 1
Reputation: 5699
I would define a flag as the ajax call is fired, then put in a setTimeout in your success.
setTimeout(check_redirect, 30000);
If error fires then set the flag to false
When the timer runs out your callback will be fired, check the flag and continue as appropriate:
function check_redirect()
{
if(flag===true)
{
location.reload(true);
}
}
Upvotes: 0