一直想把Diigo上的书签保存下来。Diigo本身提供API,那好,我就想用用看。找到示例代码:
非常奇怪的,分别在firefox3.0出现:
var API_URL = 'http://api2.diigo.com/bookmarks';
var xmlHttp = false;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){// code for IE5 and IE6
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function onResponse() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
/* GET: query bookmarks */
function queryBookmarks() {
if(xmlHttp){
try {
xmlHttp.onreadystatechange = onResponse;
xmlHttp.open("GET", "http://api2.diigo.com/bookmarks?rows=1&users=shengyan", true);
xmlHttp.send(null);
} catch (e) {
alert("Error:"+e)
}
}else{
alert('test')
}
}
[Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "file:///J:/test.html Line: 35"]这个找了很多地方,有个地方说是firefox的bug。不懂了。
但在IE下输入帐号和密码后,倒是可以争取取出来。
上述代码中使用了XMLHttpRequest(firefox或其他浏览器)或ActiveXObject(IE),从代码中可以看到XMLHttpRequest可以发送请求给服务器并得到responseText,具体可参见这里很详细的介绍了使用方法。
XMLHttpRequest更多资料:http://www.w3schools.com/XML/xml_http.asp
另外,关于User Agent。现在连上那个网址,要进行帐户验证。怎样才能让请求直接加上帐户信息呢。说是关于User Agent的,但是不知道如何加这个头。




。。。。