Suneth Kalhara
Suneth Kalhara

Reputation: 1208

JQuery AJAX async false not working on Chrome

I'm writing a jQuery for send list of form datas one by one to server.

It working perfectly on Firefox, but when i use chrome it's sending all data at once

Here is my code

    $('.frmroldcon').each(function(){       
                var thobj=this;         
                $(thobj).prev().prev().prev('.failedicoconold').hide();
                $(thobj).prev('.doneicoconold').hide();
                $(thobj).prev().prev('.proccesicoconold').show();

                fuser = jQuery('input[name="fusername"]',thobj).val();
                fpass = jQuery('input[name="fpassword"]',thobj).val();


                  $.ajax({
           type: "POST",
           async: false,
           cache:false,
           url: "checkcon.php",
           data: { checkcons: "1", fusername: fuser, fpassword: fpass},
           success: function(data){
                $(thobj).prev().prev('.proccesicoconold').hide();
                              if(data==0){
                                 $(thobj).prev().prev().prev('.failedicoconold').show();
                                  window.errc=window.errc+1;
                              }
                              else{
                                  $(thobj).prev('.doneicoconold').show();

 }                        

           }
              });                               
            });

I'm using jQuery version 2.1.4, also tried other old versions like 1.4 but it seems not working.

Can anyone give me a solution for this or alternative for submit each forms data to server one by one,

Thanks a lot

Upvotes: 1

Views: 1391

Answers (1)

Adam Jenkins
Adam Jenkins

Reputation: 55623

A quick way to do serial, asynchronous, ajax requests using jQuery's $.when

var requests = [];

$('.frmroldcon').each(function() {
    $.when.apply($,requests).then(function() {
       requests.push($.ajax({/* your ajax request */});
    });
});

You haven't shown the requirement to have to do these requests serially, however. And if you can do everything you need to do with 1 call to the server instead of 60, then that's the way you should be doing it.

Upvotes: 2

Related Questions