Home > Web Front-end > JS Tutorial > body text

Example explanation of XML in AJAX

jacklove
Release: 2018-05-09 10:15:25
Original
1375 people have browsed it

XML in AJAX is very important, so this article will explain its related knowledge in detail.

Explanation of examples - loadXMLDoc() Function

When the user clicks the "Get CD Information" button above, the loadXMLDoc() function will be executed.

The loadXMLDoc() function creates an XMLHttpRequest object, adds functions that execute when the server response is ready, and sends the request to the server.

When the server response is ready, an HTML table is built, the nodes (elements) are extracted from the XML file, and finally the txtCDInfo placeholder is updated with the HTML table that has been populated with XML data :

function loadXMLDoc(url)
{
var xmlhttp;
var txt,xx,x,i;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
txt="

";
x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
for (i=0;i {
txt=txt "
";
xx=x[i].getElementsByTagName("TITLE");
txt=txt "< td>" xx[0].firstChild.nodeValue "";
", " xx[0].firstChild.nodeValue "";
                                                                                              have 
      }
    }
  txt=txt "";
  }
  txt=txt "
TitleArtist
";
  document.getElementById('txtCDInfo' ).innerHTML=txt;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}


This article explains the XML related content in AJAX. For more learning materials, please pay attention to the php Chinese website to view.

Related recommendations:


MySQL’s first introduction to sql statements and library operations




How to pass TP5-add, delete, modify and query Simple implementation



#How to query the last record through mysql

The above is the detailed content of Example explanation of XML in AJAX. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!