Page URL delima - Controlling browser refresh
I have a page that currently goes to the url /edit/baseProductId
and it has a save functionality which creates a new product with the changes you've made. The trick here is that it's an ajax save, so the URL doesn't change. The problem is if the user refreshes the page it resets their form cause the URL wasn't updated. Is it possible for me to change baseProductId
in the URL in some way without effecting the user experience?
If I don't change the baseProductId
开发者_开发技巧or come up with some solution when the user refreshes the page it'll reset their form - or so they'll think.
Yes, change the url to /edit/baseProductId#saved
Adding the anchor adds a new item to the browser's history, so a refresh will refresh with the hash added, and changing the url this way does not reload content from the server. I don't know if all browsers will retain the info in the form fields, but you could always use jQuery to disable the form, or make it disappear entirely.
don't think so, but can't you change the base code to retrieve the values from the DB if the product exists, and populate the fields accordingly? That way, when they refresh they'll see the values they entered
You could store the form values as cookies and repopulate the inputs if the cookies are not empty on the next reload. Just bind a function to your input fields that updates the respective cookies onchange or onkeyup (might be a bit much). So you set the cookie with JavaScript then you retrieve it with your server side language on each page load.
精彩评论