How do I know if the user is updating the page

Asked

Viewed 662 times

3

The user is filling the cart with several items, and I created a jQuery function where the items are instantly added and presented to it. As soon as it finishes choosing the items and clicks on the Proceed button, the items and the value are saved in the database. But if it refreshes the page by pressing F5, or clicking on the browser image to refresh, the values and items are reset from the screen.

So far so good, the problem is are not zeroed from the bank, i would like to know how to identify this update, so I can work ajax and also erase the database data.

  • 2

    First: why would you like to erase the data if the user simply refreshes the page? Second: there is the event onbeforeunload, but it’s very limited, you can’t make asynchronous requests on your Handler.

  • The idea would be to keep one cookie. If the page is being updated, the cookie there is, otherwise no.

  • Correct is only save in the bank after it update on the screen, so I understood you save as soon as the user type?

  • Open a session on the page whenever the user accesses, destroy and starte again whenever the page is updated and save it together in the database, whenever the page is updated destroy the session and create a new one, do not forget to capture.

  • I would create an ajax to feed a php session each time an item is added. When loading the page (after F5), the session would be read in the predetermined fields. That is, you would have to work with js calculus and reading and writing session.

  • Good people, sorry for the delay, a lot of work here, I managed to solve my problem, it was just a matter of logic. It’s just that at the moment you only think about wanting to solve, resolve and, ends up not resting the mind. Thank you all.

  • If you do not want to spend spending request to add the items put them in a local session and when you want to save in the bank.

Show 2 more comments

1 answer

0

vc can use a function in onexit, and when leaving the page the function is called. What Voce would need is to know what the id of the user is, and before destroying the session, to delete the database, based on the data of Session q are destroying each other.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.