Multiple forms transfer via AJAX - synchronization or asynchronous

I have a bit of a situation where I have several forms on one page that I need to send via ajax by clicking one "Save" button. I do this by looping through forms with $ .each and then making an ajax request. Ajax requests are supposed to send a response (error / success message).

My problem is that I am mistaken using ASYNC queries, since there may be a problem with matching results that output in what form? What do you guys think?

0
source share
1 answer

Never use synchronous XHR requests; there is no good reason to use them, and this leads to a terrible user experience.

You do not need to worry about the queries being confused:

$('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. }); }); 
0
source

Source: https://habr.com/ru/post/1481655/


All Articles