目前词霸提供的接口是:
http://dict-co.iciba.com/api/dictionary.php?w=**代表要查询的单词。请高手在浏览器里试用一下(可在地址栏里输入http://dict-co.iciba.com/api/dictionary.php?w=english,回车),然后讲一下怎么用这个东西?我主要想知道能不能通过AJAX的方式来使用,我会用JS解析XML文件的。
剩100多分了,少送点,谢谢。
http://dict-co.iciba.com/api/dictionary.php?w=**代表要查询的单词。请高手在浏览器里试用一下(可在地址栏里输入http://dict-co.iciba.com/api/dictionary.php?w=english,回车),然后讲一下怎么用这个东西?我主要想知道能不能通过AJAX的方式来使用,我会用JS解析XML文件的。
剩100多分了,少送点,谢谢。
function onClicked(id)
{
var url = "http://dict-co.iciba.com/api/dictionary.php?w=" + id; var xmlHttp;
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var res = xmlHttp.responseText;
alert(typeof res);
alert(res.length);
}
}
xmlHttp.open("GET","url",true);
xmlHttp.send(null);
}
像这样吗?我试过不行,绿色语句显示 返回的字符串的长度是0
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></SCRIPT>
</HEAD> <BODY>
返回的内容:<TEXTAREA style="width:600;height:600" ROWS="10" COLS="1" id="result"></TEXTAREA><br/><br/><br/>
要查的英文单词:<INPUT id="gjz" TYPE="text" NAME="" value="english">
<INPUT TYPE="button" VALUE="获取" ONCLICK="search()">
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function search(){ var url = "http://dict-co.iciba.com/api/dictionary.php?w=" ;
$.get(url, function(data){
alert(data);
$("#result").val(data);
});
}
//-->
</SCRIPT>