Jac*_*lom 4 javascript firefox firefox-addon firefox-addon-sdk
我正在编写Firefox扩展。我正在使用与特定域匹配的内容脚本。我想从PHP页面获取数据。最终将CSS文件添加到页面以更改样式。PHP页面的内容将是我获取的CSS文件的名称。这是我的内容脚本javascript,警报什么也不返回。
有人告诉我,我受同一出身政策的限制。有什么办法可以从php页面获取数据?
function getData() {
client = new XMLHttpRequest();
try{
client.open('GET','http://localhost:8888/istyla/login/popuplogin/myaccount.php');
} catch (e){
alert( "error while opening " + e.message );
}
client.onreadystatechange = function(){
if (client.readyState ==4){
user_data = client.responseText;
var currenttheme = user_data;
alert (currenttheme);
}
}
client.send(null);
}
getData();
Run Code Online (Sandbox Code Playgroud)
您可以使用 Safari 或 IE 目前不支持的 Fetch API,但它是一个不错的选择。
你可以将它用作:
function getData(){
fetch('flowers.jpg').then(function(response) {
return response.blob();
})
}
if(self.fetch) {
// run my fetch request here
var resp = getData();
} else {
// do something with XMLHttpRequest?
}
Run Code Online (Sandbox Code Playgroud)
您可以从MDN Using Fetch API获取更多信息。您可能需要更多高级用法。
更新:你可能会发现这篇文章有用,是如此取!
归档时间: |
|
查看次数: |
13191 次 |
最近记录: |