2

I have created multiple asynchronous request with jquery like this:

       $.when(
            $.ajax({   
                url: site_url_city_1, 
                type: "GET", 
                data: window.location.search, 
                dataType: "json", 
                success: function(data) {
                    data_1 = data;
                }
            }),
            $.ajax({   
                url: site_url_city_2, 
                type: "GET", 
                data: window.location.search, 
                dataType: "json", 
                success: function(data) {
                    data_2 = data;
                }
            }),
            $.ajax({   
                url: site_url_city_3, 
                type: "GET", 
                data: window.location.search, 
                dataType: "json", 
                success: function(data) {
                    data_3 = data;
                }
            }),
            $.ajax({   
                url: site_url_city_4, 
                type: "GET", 
                data: window.location.search, 
                dataType: "json", 
                success: function(data) {
                    data_4 = data;
                }
            }),
            $.ajax({   
                url: site_url_city_5, 
                type: "GET", 
                data: window.location.search, 
                dataType: "json", 
                success: function(data) {
                    data_5 = data;
                }
            })
        ).then(function() {
           //other code
        });

I expected into the console to view all request start at the same time but isn't right.

This is my net screenshot from firebug and you can see that the last request start only when previous finished. Why? Is there a limit of asynchronous request?

enter image description here

The image is little but you can view the last two request that aren't asynchronous! The first line isn't an asynchronous request but it was into the screenshot

I need to have all request start at the same time

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
  • In short, it depends on your severside implementation. – Johan Jul 02 '14 at 08:17
  • ok but in what depends serverside? – Alessandro Minoccheri Jul 02 '14 at 08:17
  • For starters, what language are you using? – Johan Jul 02 '14 at 08:19
  • Hmm I was hoping for .NET since I have a solution there. But it seems like a common problem for concurrent ajax requests in php is the session being blocked: http://stackoverflow.com/questions/15686572/two-simultaneous-ajax-requests-wont-run-in-parallel – Johan Jul 02 '14 at 08:21
  • uhm I don't know if is the problem because I'm using codeIgniter and this function are very big but not used to write session only to return big array of data – Alessandro Minoccheri Jul 02 '14 at 08:28
  • if I create a domain of second or third level I can escape this problem? @Johan – Alessandro Minoccheri Jul 02 '14 at 08:59
  • Sorry was AFK for while. If you don't want to get involved with sessions, you could split up the php files and let each file handle its own task. That way you could send multiple requests and handle them in paralell. Not the best solution, but an option – Johan Jul 02 '14 at 11:05

2 Answers2

0

Check this SO: jQuery: Making simultaneous ajax requests, is it possible?

The browser limits you to two requests at any given time. This is part of the HTTP specification. (HTTP 1.1 specification, section 8.1.4)

Community
  • 1
  • 1
Artur Kedzior
  • 3,994
  • 1
  • 36
  • 58
0

It's not a bug. — It's a feature.

Depending on the browser, there are limits on simultaneous AJAX connections per domain and probably various methods as well. The best way to get over this is to combine the data responses into as few files as possible.

aldavigdis
  • 635
  • 6
  • 17