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

Introduction to parsing XML examples through AJAX's JS and JQuery_javascript skills

WBOY
Release: 2016-05-16 17:21:44
Original
1051 people have browsed it

JQuery version

Copy code The code is as follows:

$.ajax({
url: "order/order_orderDetail.do?params.type=merge",
type : "post",
data : params,
success : function(xml) {
hide();
if(xml == ""){
Dialog.popTip("Cannot find the order that needs to be merged", 2);
}else{
var myTable=document.getElementById( "t_product" );
//Traverse the "ORDER" node
$(xml).find('ORDER').each(function(){
var id = $(this).find("ORDERID").text ();
var status = $(this).find("STATUS").text();

if(status == "1"){
status="Unconfirmed" ;
}else{
status="Confirmed";
}

var newRow = myTable.insertRow();
var oCell = newRow.insertCell();
oCell.setAttribute("height","25");
oCell.innerHTML=" ";
oCell = newRow.insertCell();
oCell.innerHTML="*Order< ;span style="color:red">" id "'s status is:" status ", product The situation is as follows";
oCell = newRow.insertCell();
oCell.innerHTML= " ";
oCell = newRow.insertCell();
oCell.innerHTML=" ";
//Traverse the "PRODUCT" node
$(this).find('PRODUCT').each (function(){
var pid = $(this).find("PRODUCTID").text();
var pname = $(this).find("PRODUCTNAME").text();
var purl = $(this).find("PRODUCTURL").text();
var pprice = $(this).find("PRICE").text();
var pcount = $ (this).find("GOODSCOUNT").text();
newRow = myTable.insertRow();
oCell = newRow.insertCell();
oCell.setAttribute("height","25 ");
oCell.innerHTML=pid;
oCell = newRow.insertCell();
oCell.innerHTML="" pname "";
oCell = newRow.insertCell();
oCell.innerHTML=""
oCell = newRow.insertCell();
oCell.innerHTML=pprice ;
});
});
}
},
error : function() {
hide();
Dialog.popTip("Server busy", 2);
}
});

JS version
Copy code The code is as follows:

if(xmlHttp.readyState ==4){
if(xmlHttp.status ==200){
hide();
var xml = xmlHttp.responseXML;
if (xml == null){
Dialog.popTip("Cannot find the order that needs to be merged", 2);
}else{
var myTable=document.getElementById("t_product" );
var orders = xml.getElementsByTagName("ORDER");
for(var i=0;ivar order = orders[i];
var id = order .getElementsByTagName("ORDERID")[0].childNodes[0].nodeValue;
var status =order.getElementsByTagName("STATUS")[0].childNodes[0].nodeValue;
alert(status) ;
if(status == "1"){
status="Unconfirmed";
}else{
status="Confirmed";
}
var newRow = myTable.insertRow();
var oCell = newRow.insertCell();
oCell.setAttribute("height","25");
oCell.innerHTML=" ";
oCell = newRow .insertCell();
oCell.innerHTML="*Order" The status of id " is: " status ", the product status is as follows ";
oCell = newRow.insertCell();
oCell.innerHTML=" ";
oCell = newRow.insertCell();
oCell.innerHTML=" ";

var products = order.getElementsByTagName("PRODUCT");
for(var i=0;ivar product = products[i];
var pid = product. getElementsByTagName("PRODUCTID")[0].childNodes[0].nodeValue;
var pname = product.getElementsByTagName("PRODUCTNAME")[0].childNodes[0].nodeValue;
var purl = product. getElementsByTagName("PRODUCTURL")[0].childNodes[0].nodeValue;
var pprice = product.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue;
var pcount = product. getElementsByTagName("GOODSCOUNT")[0].childNodes[0].nodeValue;
newRow = myTable.insertRow();
oCell = newRow.insertCell();
oCell.setAttribute("height", "25");
oCell.innerHTML=pid;
oCell = newRow.insertCell();
oCell.innerHTML=" " pname "";
oCell = newRow.insertCell();
oCell.innerHTML=""
oCell = newRow.insertCell();
oCell.innerHTML =pprice;
}
}
}
}
}
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!