I have a big problem here. I need to wait for my ajax request before continue the rest of my code. I searched during 2 days and I found a possible solution who could maybe work. I have tried so many ways to solve my problem and now I need help. The .when().done() methods just execute a function when another function is done and don't stop the execution of my code. I don't want to use $.ajax {async:false}. I tried it, it's not recommended and its not working.
So first I execute calculerTauxUtilisation() method, who called lancerRequeteObtenirTaux() several times, where I would like to wait for traiterRequeteObtenirTaux() before to execute placerTauxUtilisation(). My problem is lancerRequeteObtenirTaux is executed several times without executing traiterRequeteObtenirTaux() and placerTauxUtilisation()
Thanks for 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);
}