Using XMLHttpRequests in Javascript
Chrome extensions are allo开发者_高级运维wed to make XMLhttpRequests outside of your own domain if you specify them in your Json file. However, after I have done this, I still get status 0 when trying to make an XMLhttpRequest. Does anyone know how to fix this?
My 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();
My Json file
{
"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/"
]
}
This is the link to the google example http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/howto/contentscript_xhr/background.html?view=markup
Looks like that permissions are related to URLs not to hosts.
Try using a wildcard
http://search.twitter.com/*
http://code.google.com/chrome/extensions/match_patterns.html
精彩评论