Submitting multiple forms at once with Ajax

This is a technical design issue, not a syntactic issue.

I have a large page with 9 forms corresponding to various tables. I was struggling with design and I have no way out, I have to submit all forms via ajax to the server for processing. There are many connections. I cannot combine shapes into one big one. So the question is what is the best way to submit a lot of forms via ajax. To further complicate the problem, there are dynamic forms with fields with the same name.

I try the technique:
1. Serialize each form, 2. add the form name to each field name 3. Merge the serialized version of the forms into one 4. Publish the merged serialized form to the server as one 5. Split them on the server side into separate arrays and then finally executing the application logic

I just don't know if there has been a tried and true lighter solution and I am making a mountain out of a molehill.

+2


source to share


3 answers


If you really do not have the opportunity to redesign the page, then your solution seems simple and straightforward to me, and not at all "mountain". To me, however, your page description screams "redesign", although of course I don't have enough information to work with.



One such redesign would be to send field changes to the server as they occur, rather than waiting and sending everything. The server side can keep them "pending" if you need the user to explicitly commit all of these when they are done. But it depends on the resource consumption of the server, etc.

+2


source


You should be able to send 9 separate AJAX requests without fuss (assuming a: each doesn't rely on the other's response, and b: that's not something that happens all the time).

Using your javascript library (you're using one, right?) Just loop through your forms and AJAX submit them. I think this will probably only be handled 2 at a time, but if that's not an issue for your design then things should be sweet.



This will surely keep the PHP / Server-Side part of the equation much simpler.

If you've been on a high traffic site, you probably want to reduce the number of requests, but chances are that your current setup will work reasonably well.

+2


source


I would prepare a javascript dispatcher that cleverly does the job of sending data. So when the submit button is clicked, it will collect all the data it needs and then send the data to the appropriate server side controllers. It can block the form, meanwhile, or display the "Processing ..." popup.

+1


source







All Articles