1👍
$.ajax({
url: "test.html",
error: function(){
// will fire when timeout is reached
},
success: function(){
//do something
},
timeout: 3000 // sets timeout to 3 seconds
});
0👍
Here is how to do it in jQuery
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
timeout: 4000 /*Miliseconds*/
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
Vinilla JS i much more complex but the code you would end up with would be something like this
xhr = new XMLHttpRequest();
// ALOT OF OTHER CODE....
xhr.timeout = 4000;
Source:stackexchange.com