Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement an ajax request queue using jQuery

What is the best way to implement an Ajax request queue using jQuery? Specifically, I want to accomplish the following:

  • A user triggers any number of Ajax requests within a web page, which need to be queued up and submitted sequentially.

  • The web page needs to receive responses from the server and adjust itself accordingly.

  • Finally, if an error occurs (connection lost, server failed to respond, etc.), I want jQuery to invoke a JavaScript function.

I'm struggling with the last requirement in particular, as the error handling mechanism in jQuery's Ajax functions is not very intuitive. Are there any examples/tutorials that could help me with this task?

Thanks!

like image 588
Tony the Pony Avatar asked Aug 29 '26 12:08

Tony the Pony


1 Answers

I've made a few buffers like this. Some examples can be found simple task Buffer and deferred item queue.

As for error handling you can always use .ajaxError

like image 199
Raynos Avatar answered Sep 01 '26 00:09

Raynos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!