dojo.cookie(id)不能间歇地通过id查找cookie

时间:2012-10-25 14:05:17

标签: javascript dojo

_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?

1 个答案:

答案 0 :(得分:1)

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

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