gpt4 book ai didi

javascript - dojo.cookie(id) 无法间歇性地通过 id 查找 cookie

转载 作者:行者123 更新时间:2023-11-28 02:38:22 24 4
gpt4 key购买 nike

_setPrintExportCookieInterval: function(/**String*/requestId, /**function*/closePopup) {
//have the interval autoexpire after some amount of seconds
var count = 0;
var intervalMs = 2000;

var intervalId = self.setInterval(function() {
var reportCookie = dojo.cookie(requestId);
console.debug('requestId ' + requestId);
if(reportCookie || count > 300000) { //5 mins
//if there's a status failure, don't close the window
console.debug('reportCookie ' + reportCookie);
if(reportCookie == undefined){
console.debug("print/export request returned with undefined status ");
} else if(reportCookie == "success") {
closePopup();
} else{
console.debug("print/export request returned with nonstandard status " + reportCookie);
}
window.clearInterval(intervalId);
//delete the cookie
dojo.cookie(requestId, null, {path: "/", expires: -1});
//destroy the iframe
//dojo.destroy(dojo.byId(requestId));
};
count+=intervalMs;
}, intervalMs);

return intervalId;
},

我在使用上述 JavaScript 函数时遇到问题。问题通常是有时:

var reportCookie = dojo.cookie(requestId);

返回null,但是当我查看浏览器的调试工具时,我可以看到该 cookie 存在,且值为 success。这种情况每调用该函数 10 次就会发生一次。知道为什么 dojo.cookie() 有时无法通过 ID 查找 cookie 吗?

最佳答案

确保在检索 cookie 时指定路径,否则默认为当前位置。这将允许您从域内的任何路径获取 Cookie。

dojo.cookie(requestId, null, {path: "/"});

关于javascript - dojo.cookie(id) 无法间歇性地通过 id 查找 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13070407/

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