Ajax Getting Started Tutorial: Ajax parsing XML file
Source: Internet
Author: User
<?xml version= "1.0" encoding= "UTF-8"?>
<lovelist>
<love>Php</love>
<love>Asp</love>
<love>Jsp</love>
</lovelist>
HTML file code is as follows, the following is mainly the Ajax creation and other code in the inside.
<title>phplamp Station AJAX explanation-Www.111cn.net-</title>
<script type= "Text/javascript" >
function Createxmlhttp () {
if (window. ActiveXObject) {
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
else if (window. XMLHttpRequest) {
Xmlhttp=new XMLHttpRequest ();
}
}
function Sendajax () {
Createxmlhttp ();
Xmlhttp.open ("Get", "Me.xml", true);
xmlhttp.onreadystatechange=process;
Xmlhttp.send (NULL);
}
function process () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
Listlove (Xmlhttp.responsexml);
}
}
}
function Listlove (obj) {
var lovenode=obj.getelementsbytagname ("Lovelist") [0];
var love=lovenode.getelementsbytagname ("Love");
var con= ' <table width= "border=" 1 ">";
for (i=0;i<love.length;i++) {
Lv=love[i].childnodes[0].nodevalue;
con+= "<tr><td>" +lv+ "</td></tr>";
}
con+= "</table>";
document.getElementById ("Love"). Innerhtml=con;
}
</script>
<body>
Click on the button to see this site collection netizens love:<br/>
<input type= "button" onclick= "Sendajax ()" value= "Click to view" >
<br/>
<div id= "Love" ></div>
</body>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service