Reputation: 35
I have code:
$this.ajaxForm({
beforeSend: function (form) {
$('input[name *= "XXX"]').each(function (index) {
$.GetJSON({
url: "XXX",
data: {
XXX: $(this).val()
}
success: function(json) {
if (json.error)
{
}
}
});
}
anotheraction();
}
});
I would like to stop execution of next part of script (in loop or before "anotheraction") until end of the previous Ajax (of course if is json.error).
Edit: I would like break a loop (when i have json.error) and return false in beforeSend
Edit2: In theory async:false should help, but doesn't work too.
It is possible?
Upvotes: 0
Views: 167
Reputation: 7244
If you want to delay an operation until a success call to the server, just include it in the success callback:
$.GetJSON({
url: "XXX",
data: {
XXX: $(this).val()
}
success: function(json) {
anotheraction();
...
}
});
Upvotes: 2