您的位置:首页 > Web前端 > JQuery

JQuery AJAX 解析获得的JSON数据

2016-06-03 12:30 447 查看
下面的解析的Json是一个二级循环。

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: "get",
url: "http://xx.xx.yy/zz",
beforeSend: function(XMLHttpRequest){
//ShowLoading();
},
success: function(data, textStatus){
$("#info").html("");
$.each(data, function(i,item){
$("#info").append(
"<div><b>" + item.pid + "</b></div>" +
"<div><b>" + item.name + "</b></div>"

);
$(data[i].children).each(function(){
$("#info").append(
" <div>" + this['id'] + "</div>" +
" <div>" + this['name'] + "</div>" +
" <div>" + this['pup'] + "</div>"

);

});
});

},
complete: function(XMLHttpRequest, textStatus){
//HideLoading();
},
error: function(){
//请求出错处理
}
});

});
});
</script>
</head>
<body>

<button>解析Json</button>
<p id="info">Info</p>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: