Web Worm
Web Worm

Reputation: 2066

updating database on user close the page

how can i update a table when a user close the page or exit from that page..................

Upvotes: 0

Views: 133

Answers (3)

John Parker
John Parker

Reputation: 54445

You can't (directly). You could however attempt to make a JavaScript unload event call (via Ajax) to the server which would then trigger the required MySQL activity.

However, you can't really rely on this happening reliably (not everyone has JavaScript installed, etc.)

What problem are you attempting to solve?

Upvotes: 3

Tor Valamo
Tor Valamo

Reputation: 33749

You can have some kind of periodic timer server-side, which resets for each request. If that timer passes the session lifetime, then the user is no longer active, and you can do whatever you need to do.

Upvotes: 2

leepowers
leepowers

Reputation: 38318

If there's pending AJAX calls you can ask the user to stay on the page by listening for the onbeforeunload event. Ultimately the user can choose to interrupt whatever pending processing needs to be done, either by navigating away, closing the window, killing the browser process, experiencing a computer crash, etc. You application should be robust enough to handle these situations.

Upvotes: 1

Related Questions