0

An AJAX request is made, and PHP echoes some data which is then returned when the PHP has finished execution, like HTML being echoed onto a page 'normally'.

Other than performing a second AJAX request, is there a way to continue PHP execution after data has been returned to the JavaScript? To, for example, update a database.

D. Clayton
  • 277
  • 2
  • 10
  • 1
    No, you have to perform another AJAX request. – Jay Blanchard Aug 05 '17 at 14:49
  • Why wouldn't you update the database in the same ajax request that returns the data? – Altimus Prime Aug 05 '17 at 15:25
  • 1
    This isn't actually a duplicate question, and in reality, yes the php can flush the buffer and continue to run after a result has been pushed. If that's what the OP is asking for I'd be glad to answer the question. – Altimus Prime Aug 05 '17 at 15:27
  • @AuntJamaima So the users view is updated rapidly and lengthy database functions do not delay the user. – D. Clayton Aug 05 '17 at 15:29
  • The way to do it then is to run an asynchronous cURL function from the php script that the first and only ajax request makes. Please look at https://stackoverflow.com/questions/36171222/async-curl-request-in-php – Altimus Prime Aug 05 '17 at 15:55
  • You may also consider https://stackoverflow.com/questions/15273570/continue-processing-php-after-sending-http-response – Altimus Prime Aug 05 '17 at 16:24

0 Answers0