Reputation: 163
So i've been struggling with this issue for a while... I want to verify the result of an ajax request in a function. I know that the ajax call doesn't end when the function ends, but I don't know how to make the above sample piece of code work.
function verify(data)
{
if(data > 5)
return false;
else
{
// ajax call
if(ajax response == "")
return false;
}
}
Upvotes: 0
Views: 166
Reputation: 83366
You need to specify verify
as the callback for your ajax call.
If you're using jQuery, it would look something like:
$.ajax('foo.asmx/Method', { dataType: 'json', success: verify });
If you'd like to use jQuery to set up a global ajax handler for any call, you can use the ajaxSuccess function.
If you're doing this natively, with an actual xhr object, I think you need something like this:
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
verify(xhr.responseText);
}
}
Upvotes: 1