0

I am using AJAX call to get the records. It will take 30 seconds to complete list the record. It is working. But if I open the same page in two windows in the browser, the first window complete the list and show after that the second window call the AJAX request and get the records.

I want to simultaneously ajax call the URL in two windows and get the results. How can I achieve this?

Here is my code,

var page="product.php?category=mobile&p=1";

$.ajax({
        url: page,
        type: 'GET',
        cache: false,
        processData:false,
        beforeSend: function(data) {
            return true;
        },
        success: function(data, textStatus, jqXHR){
            $('#dataContent').html(data);
        },
        error: function(jqXHR, textStatus, errorThrown){
        }         
});
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28
selvan
  • 1,183
  • 3
  • 16
  • 24
  • The two windows are doing this independently. Are you sure your backend is properly handling concurrent connections? – nem035 Jan 12 '17 at 05:28
  • You can't, its an asynchronous call in two different threads. best you can do is depend on the js clock and only execute the `$.ajax` at a specific second *BUT* 1 call might still take longer than the other. – Xorifelse Jan 12 '17 at 05:30
  • How to handle concurrent connections?? I just checked without database connection. It also getting same issue – selvan Jan 12 '17 at 05:36
  • I think your server should handle the thread parallel request. its not the issue in ajax. – black_pottery_beauty Jan 12 '17 at 05:49
  • I found the issue. Ajax is blocking the php session. it will not allow to start session_start() in php page. – selvan Jan 12 '17 at 06:19
  • 1
    @selvan, did you add this at the bottom of your PHP `session_write_close();`? – FreedomPride Jan 12 '17 at 06:28
  • Related – [Two simultaneous AJAX requests won't run in parallel](https://stackoverflow.com/questions/15686572/two-simultaneous-ajax-requests-wont-run-in-parallel) – Jonathan Lonowski Jan 12 '17 at 07:11
  • Yes Freedompride. It is working. thanks. – selvan Jan 12 '17 at 07:16

1 Answers1

0

It's a Browser behaviour.

If you perform a GET request to exactly the same url - it will wait until the first ends. Just change urls by appending some different parameters like appendmillisecond to the end of you ajax call and see they will execute simultaneously. becase it will treat both the request as different request.