ajax调去XMl文件
$.ajax({
url: "../xml/xml", //xml的路径及文件名
type: "GET", //数据发送方式
dataType: "xml",//数据类型
success: getmessage,//成功调去函数
error: function () {//失败调去函数
alert("服务器没有返回数据,可能服务器忙,请重试");
}
})
function getmessage(data){
$(data).find('country').each(function () {
var name = $(this).find('name').text();
alert(name);
})
}
<--XML文档-->
{
"name": "中国",
"provinces": [
{
"name": "黑龙江",
"citys": {
"city": [
"哈尔滨",
"大庆"
]
}
},
{
"name": "广东",
" citys": {
"city": [
"广州",
"深圳",
"珠海"
]
}
}
]
}
ajax调去JSON文件
$.ajax({
url:url,//xml的路径及文件名
type:"GET",//数据发送方式
dataType:"JSONP",//数据类型
success:handle,//成功调去函数
error:function(){//失败调去函数
alert("返回失败")
}
})