Wednesday, December 3, 2014

Waiting for AJAX

If you need to transfer execution of your page to somewhere else, but want to make sure you don't have any pending (jquery) ajax calls, use the $.active variable as below:

// 
// wait for pending ajax calls to finish first
// 
var timer = setInterval(function() {
 if ($.active==0) {
  clearInterval(timer);
  window.location.assign("www.google.com");
 }
}, 500);

No comments:

Post a Comment