Jquery Cookie 插件返回 [object Object]

发布于 2024-11-29 09:05:15 字数 541 浏览 0 评论 0原文

我运行的网站存在问题,当 cookie 完全禁用时,用户无法继续完成预订流程。

我使用 Jquery 和 cookie 插件,当 cookie 被禁用时,cookie 似乎总是返回 [object Object]。 检查这一点的代码是:

alert($.cookie("sourceID")); //returns [object Object]
if($.cookie("sourceID") === null || $.cookie("sourceID")=== '[object Object]'){
sourceID = 27201;
}else{
sourceID = $.cookie("sourceID");
}
alert(sourceID);  //returns [object Object]

如果用户没有启用cookie,上面的代码会尝试设置默认的sourceID。然后将其(与其他信息一起)传递到另一个构建 XML 的函数并将其传递到服务器进行处理;然而,由于 [object Object] 问题,当传递此参数时,服务器无法找到匹配的 sourceid。

I have an issue with a site i run that when cookies are disabled completely user cannot continue through a booking process.

I use Jquery and the cookie plugin, the cookie appears to always return [object Object] when cookies are disabled.
Code for checking this is:

alert($.cookie("sourceID")); //returns [object Object]
if($.cookie("sourceID") === null || $.cookie("sourceID")=== '[object Object]'){
sourceID = 27201;
}else{
sourceID = $.cookie("sourceID");
}
alert(sourceID);  //returns [object Object]

the above is trying to set a default sourceID if the user does not have cookies enabled. This is then passed (along with other information) into another function that builds XML and passes it to a server for handling; however due to the [object Object] issue when this is passed the server cannot find a sourceid that matches.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔一刀 2024-12-06 09:05:15

我找到了解决此问题的方法,因为我试图从 cookie 中检索整数值,因此可以检查返回的 cookie 值是否为数字。为此,我使用此问题的答案:验证 JavaScript 中的十进制数字 - IsNumeric() 并使用:

if(isNumeric($.cookie("sourceID"))){
sourceid = $.cookie("sourceID");
}else{
sourceid = 27201;
}

不是检查 cookie 是否返回有效值的最佳方法,但我建议将来遇到此问题的任何人都根据他们知道 cookie 应包含的内容(int、特定字符串等)进行验证

i found a work around for this issue, as i was trying to retrieve an integer value from the cookie it was possible to check to see if the value of the cookie returned was numeric. To do this i use the answer from this question: Validate decimal numbers in JavaScript - IsNumeric() and used:

if(isNumeric($.cookie("sourceID"))){
sourceid = $.cookie("sourceID");
}else{
sourceid = 27201;
}

not the best way to check that the cookie is returning a valid value but i would suggest anyone that hits this issue in the future to validate against what they know the cookie should contain (int, specific string etc)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文