Reliable way to call a function on browser close or before session timeout?
Is there a way to reliably invoke a function before the session expires or the window is closed? To avoid excessive mysql queries, my scrip开发者_开发技巧t will collect and change data variables in php $_SESSION
variables and make mysql updates when there needs to be an interaction with the database. Since I'm storing this data in this manner, is there a reliable way to ensure that this data is committed to the database before the user closes the window, or before the session expires?
I have tagged php, javascript and jquery because I'm open to any method of doing so.
Addition: Sorry, we're presuming that the client has javascript enabled. I'm in a unique situation where I don't particularly care to serve a client that isn't.
Upon much searching / discussion. I will use a setTimeout()
method to periodically commit the data to the database. The user can continue (with some possible data loss) upon return, similar to the google docs model.
精彩评论