mariam528's avatar

item get removed from cart when we go backward

hello

i am making an eCommerce application in laravel and adding products to the cart using session. whenever a product is added to the cart, it will redirect to the basket page where all cart products are shown. but i just noticed that when I add the item to the cart and after that if I click the back arrow of the browser, the item is removed from the session. everything is working fine except this. i don't get why this is happening. perhaps somebody knows about this?

0 likes
4 replies
MostafaGamal's avatar

The best solution is to warn the user with appropriate message Try this

window.onbeforeunload = function() { return "Your work will be lost."; };

Snapey's avatar

make sure you always redirect after a post request. You may find a post route that just returns a view.

make sure you update session only with POST requests and never with GET

also check the contents of session. You may only be showing the previous cache of the view not the actual session content. Pressing back CANNOT change the session state.

mariam528's avatar

i have a code for redirection. actually the thing is product is in session.. but wont show when i go backward (it will show if i refresh this previous page) i am putting data in session on redirect not by ajax.

so is there any solution to this?

Please or to participate in this conversation.