我正在使用JQuery.Cookie将javascript对象存储为cookie值:
var refinerData = {};
// Read in the current cookie if it exists:
if ($.cookie('RefinerData') != null) {
refinerData = JSON.parse($.cookie('RefinerData'));
}
// Set new values based on the category and filter passed in
switch(category)
{
case "topic":
refinerData.Topic = filterVal;
break;
case "class":
refinerData.ClassName = filterVal;
break;
case "loc":
refinerData.Location = filterVal;
break;
}
// Save the cookie:
$.cookie('RefinerData', JSON.stringify(refinerData), { expires: 1, path: '/' });
Run Code Online (Sandbox Code Playgroud)
当我在firebug中调试时,cookie值的值似乎正确格式化:
{"主题":"疾病预防和管理","地点":"孵化场山诊所","ClassName":"我有糖尿病,我能吃什么?"}
我正在用C#编写一个SharePoint Web部件来读取cookie并解析它:
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie …Run Code Online (Sandbox Code Playgroud)