[英]Cross-Origin XMLHttpRequest from Chrome Extension Returning Status 0
I am writing a Chrome Extension which needs to load some data from another site. 我正在编写一个Chrome扩展程序,该扩展程序需要从另一个站点加载一些数据。 From my research I believe I should use XMLHttpRequest for this but it returns responseText="" and status=0 for every site that I try. 从我的研究中,我相信我应该为此使用XMLHttpRequest,但是它为我尝试的每个站点都返回responseText =“”和status = 0。 The URLs that I pass into the javascript are good; 我输入到javascript中的URL很好; I have tried 我努力了
http://www.google.com
and 和
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22MSFT%22)&env=store://datatables.org/alltableswithkeys
. http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22MSFT%22)&env=store://datatables.org/alltableswithkeys
。
Am I doing something ignorant/stupid? 我在做愚昧无知的事情吗? I believe that it is something with the permissions in the manifest, but what I have now should allow both of these sites. 我相信清单中有权限,但是我现在所拥有的应该允许这两个站点。 I see no errors in my javascript console. 我在JavaScript控制台中没有看到任何错误。
The manifest: 清单:
{
"manifest_version": 2,
"name": "nnnn",
"description": "nnnn",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"storage",
"http://*.query.yahooapis.com/*",
"http://*/*",
"https://*/*"
]
}
The javascript function: javascript函数:
function getSite(queryUrl) {
var request = new XMLHttpRequest();
request.open("GET", queryUrl, true);
console.log(queryUrl);
request.onreadystatechange = function () {
console.log(request);
if (request.readyState == 4) {
if (request.status == 200) {
console.log(request.responseText);
} else {
console.log('Unable to resolve address');
}
}
};
request.send(null);
}
EDIT: http://developer.chrome.com/extensions/xhr.html This is pretty much what I have been following for guidance but apparently something has gone over my head. 编辑: http : //developer.chrome.com/extensions/xhr.html这几乎是我一直遵循的指导原则,但显然有些事情困扰了我。
I don't believe it's a permission related problem. 我不认为这是与许可相关的问题。 If it were, there would be an error message in console announcing permission problem. 如果是这样,则在控制台中会出现一条错误消息,提示权限问题。 I think there's something wrong with your XMLHttpRequest. 我认为您的XMLHttpRequest出了点问题。 Make sure the queryUrl
you pass to the function is correct. 确保传递给函数的queryUrl
是正确的。
You can use Fiddler to check out what's wrong with your request. 您可以使用Fiddler来检查您的请求出了什么问题。
我做了一些无知的事情,并且提交了表单,这导致页面刷新并在完成时丢弃了先前的XMLHttpRequest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.