0

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?

2 Answers 2

2

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();
        ...
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

I would like break a loop (when i have json.error) and return false in beforeSend
0

Yes it's possible just by using the return keyword

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.