An introduction to _javascript skills by parsing XML samples through Ajax two ways of JS and jquery

Source: Internet
Author: User
jquery version
Copy Code code 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 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= "not confirmed";
}else{
Status= "confirmed";
}

var newrow = Mytable.insertrow ();
var Ocell = Newrow.insertcell ();
Ocell.setattribute ("Height", "25");
Ocell.innerhtml= "";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "*<b> order <span style=\" color:red\ ">" +id+ "</span> status is: <span style=\" color:red\ ">" +status+ "</span></b&gt, the goods are as follows <input type=\" checkbox\ "name=\" Morder\ "value=" +id+ "onclick=\" MergeOrder (); \ ">";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "";
Traversing 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= "<a href=\" "+purl+" \ "target=\" _blank\ ">" +pname+ "</a>";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "<input Style=\ "width:20px; border:0; Text-align:center;\ "type=\" text\ "id=\" P "+pid+" \ "name=\" order.count\ "class=\" txt\ "value=" +pcount+ "readonly/> Ocell = Newrow.insertcell ();
Ocell.innerhtml=pprice;
});
});
}
},
Error:function () {
Hide ();
Dialog.poptip ("Server Busy", 2);
}
});

JS version
Copy Code code as follows:

if (Xmlhttp.readystate ==4) {
if (Xmlhttp.status ==200) {
Hide ();
var xml = Xmlhttp.responsexml;
if (XML = = null) {
Dialog.poptip ("Cannot find the order to be merged", 2);
}else{
var Mytable=document.getelementbyid ("T_product");
var orders = Xml.getelementsbytagname ("Order");
for (Var i=0;i<orders.length;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= "not confirmed";
}else{
Status= "confirmed";
}
var newrow = Mytable.insertrow ();
var Ocell = Newrow.insertcell ();
Ocell.setattribute ("Height", "25");
Ocell.innerhtml= "";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "*<b> order <span style=\" color:red\ ">" +id+ "</span> status is: <span style=\" color:red\ ">" +status+ "</span></b&gt, the goods are as follows <input type=\" checkbox\ "name=\" Morder\ "value=" +id+ "onclick=\" MergeOrder (); \ ">";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "";

var products = Order.getelementsbytagname ("PRODUCT");
for (Var i=0;i<orders.length;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= "<a href=\" "+purl+" \ "target=\" _blank\ ">" +pname+ "</a>";
Ocell = Newrow.insertcell ();
Ocell.innerhtml= "<input Style=\ "width:20px; border:0; Text-align:center;\ "type=\" text\ "id=\" P "+pid+" \ "name=\" order.count\ "class=\" txt\ "value=" +pcount+ "readonly/> Ocell = Newrow.insertcell ();
Ocell.innerhtml=pprice;
}
}
}
}
}
Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.