wait for ajax request then finish the rest ( jQuery )
Posted
by
user1725155
on Stack Overflow
See other posts from Stack Overflow
or by user1725155
Published on 2012-10-14T15:32:03Z
Indexed on
2012/10/14
15:36 UTC
Read the original article
Hit count: 185
I have a peace of jquery code:
var new = checkCP(somedata);
if(new=="hi"){
alert("Welcom");
}
function checkCP(jsData){
$.ajax({
type: "POST",
url: "Process.php",
data: jsData,
dataType: "json",
success: function(data){
if(data.match==1)
return "hi";
else
return "bye";
}
});
}
I don't know why the welcome alert never show up . I checked everything , even on PHP file the result is 1 but apparently before It wait for ajax respond it passes the
if(new=="hi"){
alert("Welcom");
}
So is there anyway to wait for ajax respond then read the rest of codes in jQuery ? Thanks.
© Stack Overflow or respective owner