jQuery Ajax解析$.ajax()
$.ajax({async:true,//默认:true(异步请求)
cache:true,//默认:true,设置为false将不会从浏览器缓存中加载请求信息
type:"POST", //默认:GET,请求方式
dataType:"xml", //服务器返回的数据类型["xml","html","script","json","jsonp"]
url:"url",//(默认:当前页地址)请求发送的地址
data:{key:"value"}, //发送到服务器的数据
error:function(xml){alert('Error Loading XML document' + xml);} //请求失败时调用
timeout:1000, //设置请求超时时间
success:function(xml){//请求成功后回调函数 参数:服务器返回数据 数据格式
$("#user").empty();
//用jQuery处理xml数据
$(xml).find("Table").each(function(){
var loginname = $(this).find("Loginname").text();
var name = $(this).find("Name").text();
$("#user").append("<li>" + loginname + "-" + name + "</li>");
});
----------------------------------------------------------------------
$(xml).find("user").each(function(i){
var loginname = $(this).find("user loginname").eq(i).text();
var name = $(this).find("user name").eq(i).text();
$("#user").append("<p>" + loginname + "</p> + "<p>" + name + "</p><br/>");
});
----------------------------------------------------------------------
$(xml).find("student").each(function(i){
var id = $(this).children("id");//取对象
var id_value= $(this).children("id").eq(i).text();//取文本
alert(id_value);//这里就是id值
alert($(this).attr("email"));//这里能显示student的email属性
$("<li></li>").html(id_value).appendTo("<ol>");
});
}
});
页:
[1]