Ajax requests with SetTimeout and clearTimeout


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.