Skip to content

Instantly share code, notes, and snippets.

@flopezluis
Created May 10, 2011 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flopezluis/964183 to your computer and use it in GitHub Desktop.
Save flopezluis/964183 to your computer and use it in GitHub Desktop.
Event Queuer while requesting data. When you have taks that cannot be done between the ajax request
var function_after_ajax = [];
function fetchData() {
$.ajax({
url: url,
method: 'GET/POST',
dataType: 'json',
data:params,
success: onDataReceived
});
function onDataReceived() {
//do stuff
var fn;
while(fn = function_after_ajax.shift()) { fn(); }
setTimeout(fetchData, 200);
}
}
//use
function_after_ajax.push(function() {
//do_things
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment