Posted By

Sullan on 07/06/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

spee66


Ajax requests with SetTimeout and clearTimeout


 / Published in: jQuery
 

  1. var reqTimeout = setTimeout(function()
  2. {
  3. alert("Request timed out.");
  4. }, 5000);
  5. var xhr = $.ajax({
  6. type: "GET",
  7. url: "http://localhost:3000/",
  8. dataType: "script",
  9. success: function() {
  10. alert("success");
  11. },
  12. error: function() {
  13. alert("error");
  14. },
  15. complete: function() {
  16. clearTimeout(reqTimeout);
  17. }
  18. });

Report this snippet  

You need to login to post a comment.