javascript - Stall submitting of a form with js/jquery? -


i have few ajax requests need complete before can submit form.

how can stall within form.submit() call until ajax requests done?

var incompleteajaxcalls = 0  // each ajax call runs incompleteajaxcalls++  // followed incompleteajaxcalls-- upon completion  myform.submit(function () {     //sleep while incompleteajaxcalls > 0; }); 

prevent form submitting, submit when ajax calls have completed

myform.submit(function (e) {     e.preventdefault();      var self = this;      $.when(        $.ajax({url: 'ajax1'}),        $.ajax({url: 'ajax2'})     ).always(function() {         self.submit();     });  }); 

edit:

for array do

myform.submit(function (e) {     e.preventdefault();      var self = this,         xhr  = [];      xhr.push(         $.ajax({url: 'ajax1'})     );      xhr.push(         $.ajax({url: 'ajax2'})     );      $.when.apply($, xhr).always(function() {         self.submit();     }); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -