Created
May 10, 2011 09:38
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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