javascript - How to set up ajax time out? -


I have this code to call AJAX after 40 seconds:

  Xmlhttp} {Xmlhttp.open ("GET", microbel, true); Xmlhttp.onreadystatechange = showResults; Xmlhttp.send (zero); Var httpTimeOut = setTimeout ("Ajaxtimeout ();", 40000); } Function ajaxTimeout () {xmlhttp.abort (); Document.getElementById ('errorShow'). InnerHTML = "Request timeout"; }   

Although I am unable to test this due to environmental constraints in my place. Can someone please tell if this is correct or any modification is necessary?

Fix it:

  if (xmlhttp) {xmlhttp .open ("GET", MY_SERVLET, is true); Xmlhttp.onreadystatechange = showResults; Xmlhttp.send (zero); SetTimeout (function () {xmlhttp.abort ()}, 40000); Since   

the ajaxTimeout function can not see the variable " xmlhttp , but we can use the anonymous function to access the local variable

Still have to use another approach so that the library can take care of it.

Your code will look like this:

  $. Ajax ({Url: MY_SERVLET, async: true, timeout: 40000, success: function (ARG) {// on success code}})    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -

java : convert string value to int -