gpt4 book ai didi

javascript - jQuery.cookie 不存储我的 JSON 字符串

转载 作者:行者123 更新时间:2023-12-02 19:14:19 26 4
gpt4 key购买 nike

所以我对 jQuery 和 JSON 很陌生,但这非常简单,而且它不起作用的事实让我很沮丧。

我有一个 ASP.NET MVC 网站。我正在使用 AJAX(通过 jQuery)加载一些数据。在那之前一切都很好。

我正在尝试使用 carhartl/jquery-cookie 将结果存储在 cookie 中。

问题是当我尝试将数据存储在 cookie 中时,数据并未真正存储。我正在使用下面的代码:

                var jsonObj = JSON.stringify(result);

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

jQuery.cookie("resultData") 返回 null

我尝试运行相同的代码,但我写的是“hello word”,而不是我的实际数据,效果很好。

有人可以帮我吗?

最佳答案

Cookie 的最大大小为 4 KB。检查一下:)尝试使用较小的 json,例如 { test : 1 } 并查看是否有效

关于javascript - jQuery.cookie 不存储我的 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13293120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com