0
点赞
收藏
分享

微信扫一扫

ajax 的简单例子

waaagh 2022-11-07 阅读 121

<html> 

<head>

<script type="text/javascript">


var xmlhttp;

//这里就是传递的一个变量 最好命名为cfun

function loadXMLDoc(cfun)

{

if (window.XMLHttpRequest)

{// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

xmlhttp.onreadystatechange=cfun;

xmlhttp.open("GET","http://www.w3school.com.cn/example/xmle/books.xml",true);

xmlhttp.send();

}


function aa()

{

var txt,x,i;

if (xmlhttp.readyState==4 && xmlhttp.status==200)

{

xmlDoc=xmlhttp.responseXML;

txt="";

x=xmlDoc.getElementsByTagName("title");

for (i=0;i<x.length;i++)

{

txt=txt + x[i].childNodes[0].nodeValue + "<br />";

}

document.getElementById("myDiv").innerHTML=txt;

}

}

</script>

</head>


<body>


<h2>My Book Collection:</h2>

<div id="myDiv"></div>

<button type="button" οnclick="loadXMLDoc(aa)">获得我的图书收藏列表</button>


</body>

</html>

举报

相关推荐

0 条评论