Ran*_*ana 7 javascript local-storage laravel
在 Laravel 中,有没有办法在控制器中获取本地存储项目。我想在视图刀片中返回这些项目。我的本地存储项目看起来像 .
我建议您使用 javascript 从 localStorage 中获取值localStorage.getItem('myItem'),然后使用document.cookie = "name=value". 您现在可以使用$_COOKIE['cookieName'].
例子:
Javascript
//define a function to set cookies
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
//get your item from the localStorage
var myItem = localStorage.getItem('myItem');
setCookie('cookieName', myItem, 7);
Run Code Online (Sandbox Code Playgroud)
PHP
$myItem = '';
if(isset($_COOKIE['cookieName'])) {
$myItem = $_COOKIE['cookieName'];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13169 次 |
| 最近记录: |