【发布时间】:2014-04-11 19:09:19
【问题描述】:
您好,我在 head-tag 中包含了 jquery.cookie-plugin,现在我正在使用这个 sn-p 来测试 cookie:
$(document).ready(function() {
$userSettings = array(
"personal_information" = array(
"name" => "name",
"last_name" => "lastname"
),
"extra_information" = array(
"twitter" => "anyName",
"facebook" => "anyName",
"website" => "http://domain.com/",
"programming_languages" => array("JavaScript", "PHP", "Java")
)
);
});
// Creating the JSON object
$jsonObject = json_encode($userSettings);
(function($){
$(document).on('ready', function(){
//A cookie by the name 'userSettings' now exists with a serialized copy of $userSettings
$.cookies.set( 'userSettings', <?php echo $jsonObject; ?> );
//A variable named 'userSettings' now holds the unserialized object, it should be identical to the PHP variable 'userSettings'
var userSettings = $.cookies.get( 'userSettings' );
// Do something with the values read from cookie
console.log(userSettings);
});
})(jQuery);
但是我的控制台中没有日志,任何人都可以告诉我我做错了什么,因为我在控制台中得到了这个参考:
ReferenceError: invalid assignment left-hand side
$userSettings = array("personal_information" = array(
你好!!
【问题讨论】:
-
那么,任何答案都有帮助吗?你设法解决了这个问题吗?请更新此 SO 项;也许您可以检查 1 个答案为“正确”...
标签: javascript jquery arrays cookies plugins