0

I have a bit of situation where I have multiple forms on the same page that I need submit via ajax by pressing a single "Save" button. I'm doing this by looping through the forms using $.each and then making the ajax request. The ajax requests are supposed to send back a response (errors / success message).

My problem is - would I be making a mistake by using ASYNC requests, as there might be a problem with matching up which output goes to which form ? What do you guys think ?

4
  • Never use synchronous XHR requests. Commented Mar 14, 2013 at 20:00
  • What he said ^^^^^^ ! Commented Mar 14, 2013 at 20:05
  • What am I missing here then ? Would async requests not have a problem with matching which output goes to what form as async requests don't wait on completion. Commented Mar 14, 2013 at 20:08
  • Not if you keep a proper order and know what you're sending etc. Commented Mar 14, 2013 at 20:10

1 Answer 1

0

Never use synchronous XHR requests; there's no valid reason to use them, and it results in terrible user experience.

You don't have to worry about the requests getting mixed up:

$('form').each(function() {
    var form = $(this);
    $.post(form.attr('action'), form.serialize(), function(r) {
        // `form` is still the particular form submitted,
        // and `r` will be the results of posting that form.
    });
});
Sign up to request clarification or add additional context in comments.

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.