Posted By

Sullan on 02/15/11


Tagged

ajax


Versions (?)

AJAX Delay for X seconds


 / Published in: jQuery
 

  1. var pendingCall = { timeStamp: null, procID: null };
  2.  
  3. $('li a').click(function (e) {
  4. e.preventDefault();
  5. var getUrl = $(this).attr("href");
  6. var timeStamp = Date.now();
  7.  
  8. var printCall = function () {
  9. $.ajax({
  10. url: getUrl,
  11. type: "GET",
  12. beforeSend: function () { },
  13. error: function (request) { alert(request) },
  14. success: function (data) {
  15. if (pendingCall.timeStamp != timeStamp) { return false; }
  16. $('#graphContent').html(data);
  17. pendingCall.procID = null;
  18. }
  19. });
  20. };
  21.  
  22. if (pendingCall.procID) {
  23. clearTimeout(pendingCall.procID)
  24. };
  25. pendingCall = { timeStamp: timeStamp, procID: setTimeout(printCall, 3000) };
  26. });

Report this snippet  

You need to login to post a comment.