jquery - How to stop code until Ajax requests are done? -


i have big problem here. need wait ajax request before continue rest of code. searched during 2 days , found possible solution maybe work. have tried many ways solve problem , need help. .when().done() methods execute function when function done , don't stop execution of code. don't want use $.ajax {async:false}. tried it, it's not recommended , not working.

so first execute calculertauxutilisation() method, called lancerrequeteobtenirtaux() several times, wait traiterrequeteobtenirtaux() before execute placertauxutilisation(). problem lancerrequeteobtenirtaux executed several times without executing traiterrequeteobtenirtaux() , placertauxutilisation()

thanks help!

Émile

var elementhoublon = null;  function calculertauxutilisation() {      var ligneshoublons = $('[id = "elementhoublon"]');     ligneshoublons.each(function (index, item) {     elementhoublon = $(item);     $.when(lancerrequeteobtenirtaux(elementhoublon.children().eq(0).children().eq(0))).done(function (taux) { placertauxutilisation (taux) });     });  }  function lancerrequeteobtenirtaux(item) {     return $.ajax({         url: "/recettes/tauxutilisation/",         data: "url=" +     "http://sv54.cmaisonneuve.qc.ca/brewmaster/houblons/tauxutilisation?" + "og=" +     $("#ogreel").val().replace(",", ".") + ",duree=" +     item.parent().next().next().next().next().children().eq(0).val(),         success: traiterrequeteobtenirtaux       }) }   function traiterrequeteobtenirtaux(taux) {     triggera = triggera + 1;     var tauxutilisation = taux; }  function placertauxutilisation(taux) {     elementhoublon.children().eq(5).children().eq().val(taux); } 

a simple (& untested) approach might work you:

function lancerrequeteobtenirtaux(item) {     return $.ajax({         …         success: function(taux){             traiterrequeteobtenirtaux(taux);             placertauxutilisation(taux);         }     }) } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -