Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue AJAX request after page refresh

I have a simple question, but can't find a quick answer. Maybe somebody here can help me.

If I trigger an AJAX request on my HTML page with jQuery and then trigger a refresh while the AJAX request isn't finished yet, does the AJAX request stop? Or does it continue on the server?

Thanks.

like image 369
Hans Avatar asked Oct 19 '25 16:10

Hans


2 Answers

The ajax request will stop. Whether or not your server processes the request will depend on whether or not the server completely received the request before it was stopped.

This is a case where it is ok to use async: false to get the behaviour you want. However, it would be better to just wait to do the refresh until the ajax is complete.

like image 78
Kevin B Avatar answered Oct 21 '25 06:10

Kevin B


I believe it depends on whether or not a session was started on the ajax page.

If yes then the php will 'block' until the ajax request was completed and the page refresh will not occur until such time.

You can however prevent this 'blocking behavior' with session_write_close(); which will leave the session open for reading but not writing

like image 31
andrew Avatar answered Oct 21 '25 06:10

andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!