There are many ways to parse XML. In this article, we will introduce the following methods: ajax js and JQuery. The specific implementation is as follows, if you are interested, refer to the JQuery version.
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 ("the order to be merged cannot be found", 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 = "*The status of the order "+ id +" is: "+ status +"The product information 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
The Code is as follows:
If (xmlHttp. readyState = 4 ){
If (xmlHttp. status = 200 ){
Hide ();
Var xml = xmlHttp. responseXML;
If (xml = null ){
Dialog. popTip ("the order to be merged cannot be found", 2 );
} Else {
Var myTable = document. getElementById ("t_product ");
Var orders = xml. getElementsByTagName ("ORDER ");
For (var I = 0; I Var 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 = "* The status of the order "+ id +" is: "+ status +"The product information is as follows: ";
OCell = newRow. insertCell ();
OCell. innerHTML = "";
OCell = newRow. insertCell ();
OCell. innerHTML = "";
Var products = order. getElementsByTagName ("PRODUCT ");
For (var I = 0; I Var 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;
}
}
}
}
}