Wednesday, May 29, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  171] [ 7]  / answers: 1 / hits: 21979  / 12 Years ago, tue, july 31, 2012, 12:00:00

I have a string value saved in to a variable, my webpage auto reloads after a certain process.. I need to know if I can get the value stored in that variable even after page refresh?



Im refreshing my web page using javascript code window.location.reload()



If not will it work if I take to server side script like php?


More From » ajax

 Answers
10

JavaScript:



  1. localStorage (HTML5 browsers only) - you could save it as a property of the page's local storage allowance



  2. save it in a cookie



  3. append the variable to the URL hash so it's retrievable via location.hash after the refresh




PHP



  1. save it as a session variable and retrieve it over AJAX each time the page loads



  2. save it in a cookie (might as well do the JS approach if you're going to cookie it)




Any PHP approach would be clunky as you'd have to first send the value of the variable to a PHP script over AJAX, then retrieve it over AJAX after reload.


[#83951] Monday, July 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grant

Total Points: 169
Total Questions: 96
Total Answers: 98

Location: Cape Verde
Member since Sat, Apr 24, 2021
3 Years ago
;