We use jquery's Ajax, time-out retries can be in two ways, one is to configure the Ajax timeout parameter, and the other is implemented in the way of the settimeout timer:
1) Timeout parameter configuration method
varXHR =$.ajax ({type:' Get ', URL:' Http://localhost:8080/user ', data:{ID:1}, timeout:5000,//set timeout time 5 secondsDataType: "JSON", Success:function(res) {if(res.success) {//Business Processing}}, Error:function(err) {if(Err.statustext = = ' Timeout ') {xhr.abort (); //Timeout Interrupt Request //Here you can re-execute the request } } })
2) settimeout Timer mode
functionRetrycallback () {varXHR; //Set 5-second timeout timer varTimer = SetTimeout (function(){ //Interrupt Last RequestXhr.abort (); //Timeout RetryRetrycallback (); }, 5000) XHR=$.ajax ({type:' Get ', URL:' Http://localhost:8080/user ', data:{ID:1}, DataType:"JSON", Success:function(res) {//Clear Timer if not timed outcleartimeout (Timer)}}) }retrycallback ()
Timeout Retry (i) Ajax