Michael Stachowsky
Michael Stachowsky

Reputation: 787

How does php handle multiple POST requests via AJAX?

I have a web page that will have a dynamic number of input fields depending on the user's preference. I am using AJAX to send the data. I'm thinking of sending the data one field at a time via individual POST requests to a single php page. That page will look at the variable that has been set and respond appropriately. If I have a single javascript function that runs a for loop, sending the POST requests as it runs through the input fields, do I get one php session for each POST, or do I get only a single one that begins, runs the script, and ends?

Upvotes: 0

Views: 603

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 8945

Be sure that you clearly understand what "a session" is, and how it relates to HTTP and therefore also to AJAX.

Ordinarily, you would bundle-up all the data and send it in one AJAX request, although you can certainly do things any way you like. Remember that AJAX requests are likely to be processed in parallel on the server, and that they might be handled in an unpredictable sequence. Therefore, it is common practice that "everything that logically 'goes together' is sent together, in one AJAX round-trip.

Your "session," meanwhile, would be established once, and then referenced (implicitly ...) in all AJAX requests, as well as in any other HTTP or HTTPS activity which occurs.

Upvotes: 2

Related Questions