[英]store php multidimensional array in localstorage
我正在建立一個網站,用戶可以在其中使用該網站並輸入數據。 但是,要保存他們的數據,他們需要登錄到我的網站(使用facebook connect)。 他們輸入的數據存儲在具有以下結構的php多維數組中:
$order = array();
$order[] = array('rank'=>'1', 'day'=>'Tues'); // This $order[] has input inputted several times by the user
// I haven't included all the code because it's big, all that's really needed is to see the structure of $order
我的問題是,如何將php多維數組轉換為javascript,然后如何使用localStorage.setItem()將其存儲到localStorage上,以便一旦他們使用facebook登錄后就可以使用該數據? 這是最好的解決方法還是我應該做其他事情?
<?php
require_once 'src/facebook.php';
$order = array();
$order[] = array('rank'=>$column, 'day'=>$day);
$loginUrl = $facebook->getLoginUrl(array('scope'=>'user_about_me,email'));
?>
<html>
<head>
<script type="text/javascript">
function fblogin() {
var fk = "<?php echo $loginUrl; ?>";
// What do I do here to convert $order into javascript?
// What do I do here to store converted $order onto localStorage()
window.location = "<?php echo $loginUrl; ?>";
}
</script>
</head>
<body>
<INPUT type="image" src="img/fb.png" onclick="fblogin()" />
</body>
</html>
json_encode()您的數組,將其發送到客戶端,並localeStorage序列化的數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.