私はディスカス通知Chromeの拡張機能を作成しています。これはdisqus.comへのHTTPコールの作成を含みますが、私はAJAXコールを取得できません - Chromeは私に有名なNETWORK_ERR: XMLHttpRequest Exception 101
エラーを与えます。私はどこかで読んChromeの拡張機能、クロスドメインAJAXはNETWORK_ERRを与える:XMLHttpRequestの例外101
は、ChromeはAJAXをアンパック拡張子から呼び出すクロスドメインをブロックすること(ここで思い出すことができない)ので、私はまた私の拡張パック試してみた - しかし、同じ結果を。また、バックグラウンドページ以外のどこからでもドメイン間AJAXを実行することはできません。
manifest.jsonを:
{
"name": "Disqus notifier",
"version": "1.0",
"description": "Get notifications when you have new replies on your Disqus posts",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"background_page": "background.html",
"permissions": [
"http://*/*",
"https://*/*"
]
}
background.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="background.js"></script>
</head>
<body>
</body>
</html>
background.js:
function poll() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = handleStateChange; // Implemented elsewhere.
xhr.open("GET", chrome.extension.getURL('http://disqus.com/api/3.0/messagesx/unread.json?user=<...>&api_key=<...>'), false);
xhr.send(null);
console.log(xhr.responseText);
}
function handleStateChange() {
if (this.readyState == 4) {
var resp = JSON.parse(this.responseText);
updateUi(resp);
}
}
function updateUi(json) {
console.log("JSON: ", json);
}
popup.html:
<html>
<head>
<title>Disqus notifier</title>
<script type="text/javascript">
function updateButtonClicked() {
chrome.extension.getBackgroundPage().poll();
}
</script>
</head>
<body>
<button type="button" onclick="updateButtonClicked()">Update</button>
</body>
</html>
xhr.send(null);
ラインは101
エラーを記録するものです。イベントハンドラhandleStateChange
では、this.responseText
はUnexpected end of input
で失敗するJSON.parse
を引き起こして、空の文字列です。
ので:私は、クロスドメインAJAX呼び出しを行うために許可されるために何をしないのですか?
。 'getURL'呼び出しは、これまでのいくつかの実験の遺物でした。ありがとうございました! –