I can't understand what I am doing wrong when trying to get these two functions to run in correct order. For some reason my modal window won't show until after the long running ajax call is completed. I went through some other posts talking about using a promise instead to block until it returns. Its turning into a house fire.
function modalShow() { //all it is doing is showing a div...
var deferred = $.Deferred();
var show = function () {
if (!$("#myModal").is(":visible"))
{
console.log("showing modal");
$("#myModal").show();
setTimeout(show,500);
} else {
console.log("marking deferred");
deferred.resolve(true);
}
}
show();
return deferred.promise();
}
function saveData(id) {
var promise = modalShow();
promise.then(function () {
console.log("continuing");
'super long ajax call
});
setTimeout(saveData(id),500);
}
What I keep ending up with is first no modal popup of any kind even though i run the showModal() on its own and works fine and a never ending loop of
marking deferred
continuing
marking deferred
continuing
marking deferred
continuing
marking deferred
continuing
marking deferred
Any ideas what I am doing wrong? Looked at a fair number of examples and don't see what I am missing. thanks