Reputation: 39
I have already searched on the site how to wait until the ajax function is done and i found this solution:
function next() {
$.when(checksign()).done(function () {
if (uf == 1) {
$("#usrdiv").css("display", "none");
$("#pswdiv").css("display", "inline");
}
});
}
function checksign() {
$.ajax({
url: "checkuser.php",
data: {
user: u
},
method: "POST"
}).done(...);
}
but it still not working, it doesn't wait the ajax is done but direcly executes the function inside done()
Upvotes: 0
Views: 881
Reputation: 318182
That's because checksign
doesn't return the promise you need to chain on a done
function.
You don't need the $.when
wrapper for one single promise either
function next() {
checksign().done(function(data) {
if (uf == 1) {
$("#usrdiv").css("display", "none");
$("#pswdiv").css("display", "inline");
}
});
}
function checksign() {
return $.ajax({
url: "checkuser.php",
data: {
user: u
},
method: "POST"
}).done(...);
}
Upvotes: 2