I want to assign value to global variable in javascript from jquery ajax function.
var trueFalse;
$.ajax({
type: "GEt",
url: "url",
data: "text=" + $("#text").val(),
success: function(msg) {
if(msg.match(/OK/) != null) {
trueFalse = "true";
}
else {
trueFalse = "false";
}
}
});
return trueFalse;
here i need the value of trueFalse from success function.
thanks
v.srinath
If you really can’t change the application logic, then you have to create a “synchronous” ajax request (by setting
async:falsein$.ajaxoptions), then it will wait until the “GET” has executed and only then return the value to the caller.Otherwise, you should rewrite the code so that the success function calls back into some callback function that it can now proceed with whatever has to be done.