0

In short,

  1. I have a form with submit button and an ajax function which takes about 10 seconds to finish (it calls another .php file to update some records backend).

  2. I just noticed that if I have the ajax function "ongoing" (in the process of that 10 seconds). The form submission will wait for that 10 seconds ajax call return then submit. (or maybe it's submitting but the form submission takes 10 seconds anyway)

  3. If I wait until the ajax call returns then submit, it only takes 1 second to submit the form.

I thought ajax should be "async" and should not block anything on the page? Am I wrong? How should I make it "async" so it does not block any other links or submit buttons on the page while the ajax is running?

To be clear: I'm trying to submit the form and have the ajax call running in parallel.

jackhao
  • 3,457
  • 3
  • 22
  • 43
  • Please show us the relevant code. It's unclear what you're trying to accomplish. Are you trying to do an Ajax call and then after that completes, submit the form? Or are you trying to do the ajax call and the form submit in parallel at the same time? – jfriend00 Oct 18 '15 at 02:39
  • This may be due to PHP and possibly how your application/server is configured. If you're using sessions, PHP can enforce a limit of one request at a time per session, so it may not begin to handle the `
    ` request until the Ajax request has completed. [Simultaneous Requests to PHP Script](http://stackoverflow.com/questions/1430883/simultaneous-requests-to-php-script)
    – Jonathan Lonowski Oct 18 '15 at 02:40
  • @jfriend00 hi there, it's a very generic situation so I didn't post specific code. I'm trying to an ajax call and submit the form in the same time. I've added that into supplement. thanks for the help! – jackhao Oct 18 '15 at 02:41
  • It very well could that that your PHP can only handle one request at a time. We can't possibly know without knowing your whole setup. You can verify both requests are being sent one after another by just looking at the network tab in the browser. – jfriend00 Oct 18 '15 at 02:41
  • @JonathanLonowski Thanks! That's probably it. Let me check that link. Thank you! – jackhao Oct 18 '15 at 02:42
  • @jfriend00 Thank you. You are right. Switching to a DB session solved the issue. – jackhao Oct 18 '15 at 02:56

1 Answers1

0

Seems like switching from a file stored session -> database based session system solves the issue. It's indeed PHP that limits 1 request per session.

jackhao
  • 3,457
  • 3
  • 22
  • 43