Reputation: 1270
I have 20 pages, each page contains 30 li
tags like below,
<li id="1">1<li/>
<li id="2">2<li/>
<li id="3">3<li/>
<li id="4">4<li/>
<li id="5">5<li/>
...
I would fire an ajax(.getJSON())
call like multi thread for each li
tag,
I did this one using the following jQuery code, but it is one by one ajax (.getJSON) calls,
it takes 2 seconds (business logic + presentation logic) to complete one ajax call. To load total page it is taking 60sec (2x30).
jQuery(li).each(function(e) {
jQuery.getJSON(JSonUrl,{},
function(json) {
// AJAX Response.
if (json == null) {
} else {
var jsonList = json.deviceStatusString.split(',');
var jsonInnerList = jsonList[0].split('#');
...
}
}
);
});
Could you please help me to fire all ajax calls like java multi thread?
Upvotes: 4
Views: 9608
Reputation: 14747
If you're hitting performance bumps with multiple AJAX request, one of the things you should always look into trying to do is to minimize all those AJAX calls into fewer calls, best if you could throw all of it into just one AJAX call.
That way, you're getting rid of a whole heap of overhead related to throwing and maintaining multiple HTTP requests.
Upvotes: 1
Reputation: 16955
I believe you are hitting a maximum number of requests limit, and so your browser is waiting until more threads become available. Check out this thread: How many concurrent AJAX (XmlHttpRequest) requests are allowed in popular browsers?
Upvotes: 4