ajax对xml的解析
<?xml version="1.0" encoding="UTF-8"?>
<stulist>
<student email="1@1.com">
<name>zhangsan</name>
<id>1</id>
</student>
<student email="651518854.com">
<name>lisi</name>
<id>2</id>
</student>
</stulist>
<script type="text/javascript">
$.ajax({
url:'ajax.asp',
type: 'GET',
dataType: 'xml',
timeout: 1000,
error: function(xml){
alert('Error loading XML document'+xml);
},
success: function(xml){
$(xml).find("student").each(function(i){
var id=$(this).children("id"); //取对象
var idvalue=$(this).children("id").text(); //取文本
alert(id_value);//这里就是ID的值了。
alert($(this).attr("email")); //这里能显示student下的email属性。
//最后么输出了,这个是cssrain的写法,貌似比macnie更JQ一点
$('<li></li>').html(id_value).appendTo('ol');
});
}
});
</script>
ajax数据集合组合的用法
function displayData(pageNo){
$("#table_data").empty();
var condi = {
pageNo:(pageNo + 1),
"taglists":$("#taglists").val(),
"startDate":$("#startDate").val(),
"endDate":$("#endDate").val(),
"findDate":$("#findDate").val(),
"sourcestyle":$("#sourcestyle").val(),
"batchid":$("#batchid").val()
};
$.ajax({
type:"POST",
async:false,
cache: false,
url:"${pageContext.request.contextPath}/stat/constatsList.action",
data: condi,
beforeSend:function(){
loading();
},
success:function(json) {
if(json.data != undefined){
var htmlString = "";
htmlString+="<tr>";
htmlString+="<td colspan='3'>总计</td>";
htmlString+="<td>"+json.allcount+"</td>";
htmlString+="<td>"+json.linkcount+"</td>";
htmlString+="<td>"+json.othercount+"</td>";
htmlString+="<tr>";
$.each(json.data, function(i, n) {
if (n!=null) {
htmlString+="<tr>";
htmlString+="<td>"+ (i+1) +"</td>";
htmlString+="<td>四级标签</td>";
htmlString+="<td>"+n.tagname+"</td>";
htmlString+="<td>"+n.allCount+"</td>";
htmlString+="</tr>";
}
});
$("#table_data").html(htmlString);
parent.parent.SetWinHeight("iframe");
}
close();
}
});
}