DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 通過AJAX的JS、JQuery兩種方式解析XML示例介紹
通過AJAX的JS、JQuery兩種方式解析XML示例介紹
編輯:關於JavaScript     
JQuery版
復制代碼 代碼如下:
$.ajax({
url : "order/order_orderDetail.do?params.type=merge",
type : "post",
data : params,
success : function(xml) {
hide();
if(xml == ""){
Dialog.popTip("找不到需要合並的訂單", 2);
}else{
var myTable=document.getElementById( "t_product" );
//遍歷"ORDER"節點
$(xml).find('ORDER').each(function(){
var id = $(this).find("ORDERID").text();
var status = $(this).find("STATUS").text();

if(status == "1"){
status="未確認";
}else{
status="已確認";
}

var newRow = myTable.insertRow();
var oCell = newRow.insertCell();
oCell.setAttribute("height","25");
oCell.innerHTML=" ";
oCell = newRow.insertCell();
oCell.innerHTML="*<b>訂單<span style=\"color:red\">"+id+"</span> 的狀態為:<span style=\"color:red\">"+status+"</span></b>,商品情況如下<input type=\"checkbox\" name=\"mOrder\" value="+id+" onclick=\"mergeOrder();\">";
oCell = newRow.insertCell();
oCell.innerHTML=" ";
oCell = newRow.insertCell();
oCell.innerHTML=" ";
//遍歷"PRODUCT"節點
$(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="<img style=\"cursor: pointer; vertical-align: middle\" src=\"./images/-.png\" onclick=\"return plus('p"+pid+"','"+pprice+"')\" /><input style=\"width: 20px; border: 0; text-align: center;\" type=\"text\" id=\"p"+pid+"\" name=\"order.count\" class=\"txt\" value="+pcount+" readonly /><img style=\"cursor: pointer; vertical-align: middle\" src=\"./images/+.png\" onclick=\"return add('p"+pid+"','"+pprice+"')\">"
oCell = newRow.insertCell();
oCell.innerHTML=pprice;
});
});
}
},
error : function() {
hide();
Dialog.popTip("服務器繁忙", 2);
}
});

JS版
復制代碼 代碼如下:
if(xmlHttp.readyState ==4){
if(xmlHttp.status ==200){
hide();
var xml = xmlHttp.responseXML;
if(xml == null){
Dialog.popTip("找不到需要合並的訂單", 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="未確認";
}else{
status="已確認";
}
var newRow = myTable.insertRow();
var oCell = newRow.insertCell();
oCell.setAttribute("height","25");
oCell.innerHTML=" ";
oCell = newRow.insertCell();
oCell.innerHTML="*<b>訂單<span style=\"color:red\">"+id+"</span> 的狀態為:<span style=\"color:red\">"+status+"</span></b>,商品情況如下<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="<img style=\"cursor: pointer; vertical-align: middle\" src=\"./images/-.png\" onclick=\"return plus('p"+pid+"','"+pprice+"')\" /><input style=\"width: 20px; border: 0; text-align: center;\" type=\"text\" id=\"p"+pid+"\" name=\"order.count\" class=\"txt\" value="+pcount+" readonly /><img style=\"cursor: pointer; vertical-align: middle\" src=\"./images/+.png\" onclick=\"return add('p"+pid+"','"+pprice+"')\">"
oCell = newRow.insertCell();
oCell.innerHTML=pprice;
}
}
}
}
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved