[jQuery] tool: pileUp
[jQuery] tool: pileUp
Hi all,
In some situations, it's useful to wait for the end of an xhr before
submitting the next one. Here is a function which implements this
behaviour. You can use it instead of $.post to guarantee the order of
responses.
$.pileUp = function(url, data, ret, type) {
function ret2(xml) {
ret(xml);
$.pileUp.heap.shift();
if ($.pileUp.heap.length) {
$.pileUp.heap[0]();
}
}
$.pileUp.heap.push(function(){$.post(url, data, ret2, type);});
if ($.pileUp.heap.length == 1) {
$.post(url, data, ret2, type);
}
};
$.pileUp.heap = [];
There's a test page here: http://fmarcia.info/jquery/pileUp/test.html.
Happy coding,
Franck.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/