简体   繁体   中英

Save a Javascript variable between user interactions?

Setting global variables in my js file doesn't seem to work. How can I set rails session variables from JavaScript?

I'd like a solution that doesn't use jQuery.


Edit : The solution is to use an HTML form containing hidden fields.

Global variables only live for the duration of a page view. Once the page is rerendered, they are reset to what their default values are.

If you need to keep the values, you need to use cookies or local storage. Other option is to submit them to the server with Ajax and have the server remember them and set the values when the page is rendered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM