注意url为网络路径
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(){
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var tempStr=xmlhttp.responseText;
alert(tempStr);
var people=eval('('+tempStr+')');
alert(people.authors[0].lastName);
}
}
xmlhttp.open("GET","http://www.cngef.org.cn/a.txt",false);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">请求数据</button><div id="myDiv"></div>
</body>
</html>