Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中使用XMLHttpRequests_Javascript_Json_Xmlhttprequest_Google Chrome Extension - Fatal编程技术网

在Javascript中使用XMLHttpRequests

在Javascript中使用XMLHttpRequests,javascript,json,xmlhttprequest,google-chrome-extension,Javascript,Json,Xmlhttprequest,Google Chrome Extension,如果您在Json文件中指定了Chrome扩展,则允许Chrome扩展在您自己的域之外生成XMLhttpRequests。但是,在完成此操作之后,在尝试进行XMLhttpRequest时,状态仍然为0。有人知道如何解决这个问题吗 我的javascript: var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { alert(xhr.status);

如果您在Json文件中指定了Chrome扩展,则允许Chrome扩展在您自己的域之外生成XMLhttpRequests。但是,在完成此操作之后,在尝试进行XMLhttpRequest时,状态仍然为0。有人知道如何解决这个问题吗

我的javascript:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
   if (xhr.readyState == 4) {
   alert(xhr.status);
       if (xhr.status == 200) {
       alert(xhr.responseText);
       }
   }   
}
var url = "http://search.twitter.com/trends/current.json?exclude=hashtags";
xhr.open("GET", url, true);
xhr.send();
我的Json文件

{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  },
  "permissions": [
    "http://search.twitter.com/"
  ]
}

这是指向google示例的链接

看起来权限与URL相关,而不是与主机相关。 尝试使用通配符

http://search.twitter.com/*

仍然返回0,因为状态是我按照使用代码的步骤尝试的,并且在没有通配符的情况下获得状态200works。编辑后是否刷新扩展?您应该提到跨源错误,这在imo中非常重要。