jQuery Limit The Number Of Simultaneous AJAX Requests

ajax, javascript, jquery

Solution

The best way to do this is letting the browser deal with it. Usually browsers already have a per-host connection limit so they will automatically queue connections if there are too many.

However, I'd consider changing the API so it takes date from multiple elements and also returns data for multiple elements - i.e. reducing the overall count of HTTP requests necessary.

Problem

so I have a series of AJAX events I would like to fire, but I want to limit the number of simultaneous requests to 5, and queue up the rest. So for example, I have the following: ``` $("div.server").each(function() { $.ajax(....); }); ``` So there may be 100 divs with the class `server`, but I want to only run 5 requests at any given time. Once a request finishes it should proceed to the next. What is the best way to do this?

Original source