缓存API-添加XMLHttpRequest对象

问题描述

我刚刚开始使用javascript的Cache API。我需要在所有GET请求中设置标头,因此我将请求对象传递给了如下所示的“ add”方法

        //Request object construction
        let xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function() { 
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                console.log(xmlHttp.responseText);
            }
        };
        xmlHttp.open("GET",reqURL,true);
        xmlHttp.setRequestHeader('MY-HEADER',myHeaderValue);
        xmlHttp.setRequestHeader('Content-Type','application/json');
        xmlHttp.setRequestHeader('X-Requested-With','XMLHttpRequest'); 

        //Cache operations
        let cacheObj = await 
            caches.open(cacheName),result = await cacheObj.match(reqURL,options);
        if(emberUtils.isNone(result)) {
            cacheObj.add(xmlHttp);
        } else {
            console.log("match found");
            console.log(result);
        }

但是,不是构造的请求对象,而是使用直接附加到基本URL的XMLHttpRequest来发送请求,例如www.mytestforcaching.com/[object%20XMLHttpRequest]。请帮助我发送构造的请求对象或在对缓存api的请求中设置标头。

预先感谢:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)