简体   繁体   English

正确初始化localstorage的方法?

[英]Correct way to initialize localstorage?

I am creating an app for google chrome that makes heavy use of local storage and so far worked wonderfully, that is until I cleaned chrome's cache and now no matter what, is not setting any local storage variables where before the cache cleaning it worked beautifully. 我正在创建一个谷歌浏览器的应用程序,大量使用本地存储,到目前为止工作非常好,直到我清理铬的缓存,现在无论如何,没有设置任何本地存储变量在缓存清理之前它工作得很漂亮。

I have a file called valtransfer.php that receives php values via something like this: 我有一个名为valtransfer.php的文件,它通过以下方式接收php值:

$_SESSION['id_area']=$_REQUEST['id_area'];

and then later down the file after the mandatory $(document.ready(function ()) bla bla I have a line like this to pass the values from the php session variable to a local storage: 然后在强制$(document.ready(function())bla bla之后将文件放下来我有一行像这样将php会话变量中的值传递给本地存储:

localStorage.setItem("id_area",'<?php echo $_SESSION['id_area']?>');

As previously said, it worked beautifully... until I cleared cache to test the application, is there something I am missing in order to prepare the browser to work with localstorage like initializing or something? 如前所述,它工作得很漂亮...直到我清除缓存以测试应用程序,是否有一些我缺少的东西,以准备浏览器使用localstorage如初始化或什么?

remove single quote and try like this. 删除单引号并尝试这样。 because php echo treat as a string 因为php echo视为一个字符串

var sessionId =  <?php echo $_SESSION['id_area']?>;

localStorage.setItem("id_area", sessionId);

试试这样吧

localStorage.setItem("id_area","<?php echo $_SESSION['id_area']?>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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