我目前正在为我的学校开发Chrome扩展程序,该扩展程序会在学校网站更新时通知学生。我已经想出如何告诉chrome我将要进行跨源请求。但我一直试图得到这个请求。我在bg.js中有以下代码:
var checkUrl="http://www.some_website.com/";
var firstCheck = false;
window.setInterval(checkForUpdate, 10000);
var pageLoad = new Date().getTime();
function checkForUpdate() {
$.ajax(checkUrl, {
ifModified : true,
type : 'HEAD',
success : function (response, status, xhr) {
if (firstCheck === false) {
firstCheck = true;
return;
}
console.info(response); //ALWAYS outputs 'undefined'
console.info(status); //ALWAYS outputs 'undefined'
// if the server omits the 'Last-Modified' header
// the following line will return 0. meaning that
// has not updated.
var lastModified = new Date(xhr.getResponseHeader('Last-Modified')).getTime();
console.info(lastModified);//ALWAYS outputs 0
if (lastModified > pageLoad) {
alert("modified TEST"); //Will change later
}
}
});
}
这个manifest.json:
{
"manifest_version": 2,
"name": "Hyperion",
"version": "0.0.1",
"description": "TEST",
"icons": {"16":"icons/icon16_chk.png"},
"background": {
"scripts":["javascript/jquery-3.2.0.min.js","javascript/bg.js"],
"persistent":false
},
"permissions":["http://*/", "https://*/"],
"browser_action": {
"default_icon":"icons/icon16_chk.png",
"default_title":"Nothing has changed!"
}
}
为什么请求和状态始终未定义'为什么我无法在响应中看到Last-Modified标头
任何帮助将不胜感激! //奥斯卡