Hans
Hans

Reputation: 568

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.

Upvotes: 4

Views: 1523

Answers (3)

andrew
andrew

Reputation: 9583

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

Upvotes: 1

ajaykalyanynr
ajaykalyanynr

Reputation: 35

it will be aborted immediately from client side, but it could make changes to database if it having some update operations

Upvotes: 0

Kevin B
Kevin B

Reputation: 95020

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.

Upvotes: 2

Related Questions