我正在尝试让Firefox插件从HTTP get中读取数据,解析结果,并在类似书签的下拉菜单中将它们显示为链接。
我的问题是:有没有人有可以做到这一点的示例代码?
发布于 2008-09-02 17:57:35
我自己从来没有开发过一个插件,我不确定在火狐插件中这通常是如何完成的,但是由于插件脚本是JavaScript的,我可能可以帮助解决加载部分的问题。假设一个名为url的变量包含您想要请求的URL:
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function() {
if(this.readyState == 4) { // Done loading?
if(this.status == 200) { // Everything okay?
// read content from this.responseXML or this.responseText
} else { // Error occurred; handle it
alert("Error " + this.status + ":\n" + this.statusText);
}
}
};
xmlhttp.send(null);关于这段代码有几点注意事项:
https://stackoverflow.com/questions/40125
复制相似问题