<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>ajax.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(function(){
$("#JSONbutton").bind("click",function(){
$.getJSON("../../page/json/demo.json",function(data){
alert(data);
//jquery 对json 的语法格式要求比较严格...
alert(data.total);
var array=data.rows;
alert(array[0].username);
alert(array[1].age);
alert(array[2].sex);
});
})
})
</script>
</head>
<style type="text/css">
</style>
<body>
<input type="button" id="JSONbutton" value="getjson提交">
</body>
</html>
demo.json
{
"total":189,
"rows":[
{"username":"zhangsan"},
{"age":18},
{"sex":"weizhi"}
]
}