简体   繁体   English

jQuery.cookie没有存储我的JSON字符串

[英]jQuery.cookie not storing my JSON string

So I'm new to jQuery and JSON but this is pretty straight forward and the fact the it isn't working is frustrating me. 所以我是jQuery和JSON的新手,但这很直接,而且它不起作用的事实令我感到沮丧。

I have an ASP.NET MVC Web site. 我有一个ASP.NET MVC网站。 I'm using AJAX (through jQuery) to load some data. 我正在使用AJAX(通过jQuery)来加载一些数据。 Everything is well and good up until there. 一切都很好,直到那里。

I'm trying to store my result in a cookie by using carhartl / jquery-cookie. 我正在尝试使用carhartl / jquery-cookie将结果存储在cookie中。

The problem is when I try to store my data in a cookie the data isn't really stored. 问题是当我尝试将数据存储在cookie中时,数据并未真正存储。 I'm using the code below: 我正在使用以下代码:

                var jsonObj = JSON.stringify(result);

                jQuery.cookie("resultData", jsonObj, {
                    expires: 2,
                    path: "/",
                    json: true
                });

jQuery.cookie("resultData") returns null jQuery.cookie("resultData")返回null

I've tried running the same code but instead of my actual data I wrote "hello word" which worked just fine. 我试过运行相同的代码,但我写了“hello word”而不是我的实际数据。

Can anyone help me please ? 有人可以帮我吗?

The max size of a cookie is 4 KB. cookie的最大大小为4 KB。 Check that :) Try with a smaller json, like { test : 1 } and see if that works 检查:)尝试使用较小的json,如{test:1},看看是否有效

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

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