【发布时间】:2014-01-30 08:59:53
【问题描述】:
我正在开发一个需要支持 ajax 请求的 firefox 插件。请求将全部发送到“messagebeam.tagpulse.nl”域,因此我将其添加到 package.json 中的权限中,如下所示:
{
"name": "messagebeam",
"title": "Message Beam for Android™",
"id": "jid1-j831e5AVhpvjDA",
"description": "With one click bidirectionally beam anything you want between Chrome and your Android device!",
"permissions": {
"cross-domain-content": ["http://messagebeam.tagpulse.nl/"]
},
"author": "TwZ",
"license": "MPL 2.0",
"version": "0.3"
}
到目前为止一切顺利。在我的 main.js 中,我定义了一个(非常基本的)小部件和一个面板(在 main.js 中)来演示问题:
var testPanel = require("sdk/panel").Panel({
width:430,
height:500,
contentURL: data.url("test.html"),
contentScriptFile: [
data.url('scripts/jquery-2.1.0.js'),
data.url('test.js')
]
});
var widgets = require("sdk/widget");
var tabs = require("sdk/tabs");
var widget = widgets.Widget({
id: "test-popup",
label: "Message Beam",
contentURL: data.url("img/test.png"),
panel: testPanel
});
test.html 很基础(没有内容):
<html>
<head>
</head>
<body>
No content
</body>
</html>
test.js(产生权限被拒绝错误的实际代码):
$(document).ready(function() {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
console.log('finished');
console.log(xmlhttp.responseXML);
console.log('reported xml');
}
}
xmlhttp.open("GET","http://messagebeam.tagpulse.nl/test/test2.php",true);
xmlhttp.send();
});
返回的xml如下(内容类型:text/xml响应头,使用http://messagebeam.tagpulse.nl/test/test2.php测试):
<?xml version="1.0" encoding="UTF-8" ?>
<test>
text
</test>
现在的问题是:为什么console.log(xmlhttp.responseXML) 行会产生以下错误:
console.log: messagebeam: finished
System JS : ERROR resource://gre/modules/XPIProvider.jsm -> jar:file:///c:/users/js/appdata/local/temp/tmpfcjrsq.mozrunner/extensions/jid1-j831e5AVhpvjDA@jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://gre/modules/commonjs/sdk/content/content-worker.js:81
Error: Permission denied to access property 'toJSON'
【问题讨论】:
标签: ajax xmlhttprequest firefox-addon-sdk permission-denied