<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> javascript
<html xmlns="http://www.w3.org/1999/xhtml"> html
<head> java
<title></title> jquery
<script src="JS/jquery-1.8.0.min.js" type="text/javascript"></script> ajax
<script type="text/javascript"> json
$(function () { 數組
$.ajax({ url
url: 'jsondata.ashx', spa
type: 'GET', xml
dataType: 'json',
timeout: 1000,
cache: false,
beforeSend: LoadFunction, //加載執行方法
error: erryFunction, //錯誤執行方法
success: succFunction //成功執行方法
})
function LoadFunction() {
$("#list").html('加載中...');
}
function erryFunction() {
alert("error");
}
function succFunction(tt) {
$("#list").html('');
//eval將字符串轉成對象數組
//var json = { "id": "10086", "uname": "zhangsan", "email": "zhangsan@qq.com" };
//json = eval(json);
//alert("===json:id=" + json.id + ",uname=" + json.uname + ",email=" + json.email);
var json = eval(tt); //數組
$.each(json, function (index, item) {
//循環獲取數據
var name = json[index].Name;
var idnumber = json[index].IdNumber;
var sex = json[index].Sex;
$("#list").html($("#list").html() + "<br>" + name + " - " + idnumber + " - " + sex + "<br/>");
});
}
});
</script>
</head>
<body>
<ul id="list">
</ul>
</body>
</html>