简体   繁体   English

Chrome扩展程序的跨域XMLHttpRequest返回状态0

[英]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.

相关问题 Chrome扩展程序将数据发布到Rails服务器跨域XMLHttpRequest - Chrome Extension Post Data to Rails Server Cross-Origin XMLHttpRequest 是否可以从Chrome中的内容脚本执行跨域XMLHttpRequest? - Is it possible to perform a Cross-Origin XMLHttpRequest from a content script in Chrome? Chrome扩展中的跨源XMLHttpRequest - Cross-Origin XMLHttpRequest in chrome extensions 用于 chrome 扩展的 iFrame 的跨域问题 - Cross-Origin issue with iFrame for chrome extension Chrome扩展程序中的跨域XHR失败 - Cross-Origin XHR failed in Chrome extension 从 Chrome 扩展程序执行跨源请求时存在 XMLHTTPRequest 漏洞? - XMLHTTPRequest vulnerabilities when doing cross origin requests from a Chrome extension? Chrome:XMLHttpRequest无法加载,跨域请求错误 - Chrome: XMLHttpRequest cannot load, cross-origin request error Chrome扩展程序的内容脚本中出现XSS“使用访问跨域框架阻止了框架的起源”错误 - XSS “Blocked a frame with origin from accessing a cross-origin frame” error in content script for a Chrome extension 阻止具有原始 chrome-extension 的框架访问跨源框架 - Blocked a frame with origin chrome-extension from accessing a cross-origin frame Chrome 扩展 - 未捕获的 DOMException:阻止具有源的框架访问跨域框架 - Chrome Extension - Uncaught DOMException: Blocked a frame with origin from accessing a cross-origin frame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM