Home Sending two AJAX requests at the same time
Reply: 0

Sending two AJAX requests at the same time

user1958
1#
user1958 Published in April 19, 2018, 8:54 pm

I am probably missing something very simple here, but what I am trying to do is update two divs on my page with AJAX requests that are called at the same time when an item is clicked.

I have looked at Two ajax requests on same event at same time . what should be the typical behaviour? how it is different if request is synchronous but unfortunatelly I am still missing something in the code.

I have the following javascript code

$(document.body).on('click', '.details', function(event) 
{
//  $(this) = your current element that clicked.
// additional code
var id = event.target.id;
//alert(id);
//alert($(this));
    _formurl    =   "home_stocktake_locations_list_group.php";
    _formdata   =   {'store_id' : id};
    _formurl2   =   "home_stocktake_list.php";
    $.ajax({ 

     type: "GET",
      url: _formurl,
      data: _formdata,
     success: function(xhrResponse)
     {
        $('#current').html(xhrResponse);
        var rowCount = $('#locations').length;          
        row_count = parseInt(rowCount) ;
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) 
      {
        $('#alert_msg').html(errorThrown);
        $('#alert_msg').fadeIn( "slow");

      }
}),
$.ajax({ 

     type: "GET",
      url: _formurl2,
      data: _formdata,
     success: function(xhrResponse)
     {
        $('#previous').html(xhrResponse);
        var rowCount = $('#dd_home_stocktake').length;          
        row_count = parseInt(rowCount) ;
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) 
      {
        $('#alert_msg').html(errorThrown);
        $('#alert_msg').fadeIn( "slow");

      }
});

});

When I look at what happens in the console, only home_stocktake_locations_list_group.php file gets called, the 2nd ajax is completely ignored. What is causing this?

In the console I can only see the following

request

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318627 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO