52,797
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
</head>
<body>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<table id="tab">
<tr>
<th>姓名</th>
<th>地址</th>
<th>电话</th>
</tr>
</table>
<input type="button" value="获取" onclick="read();" />
<script type="text/javascript">
function read() {
$.ajax({
url: "xxx.php",
type: "POST",
dataType: "json",
success: function (data) {
data.forEach(function(v, i){
var tr = $("<tr>").appendTo("#tab");
$("<td>").text(v.name).appendTo(tr);
$("<td>").text(v.address).appendTo(tr);
$("<td>").text(v.phone).appendTo(tr);
});
}
});
}
</script>
</body>
</html>
在xxx.php返回输出如下json格式的数据
[
{"name":"张三","address":"xx省xx市xx区a街道","phone":"13643666432"},
{"name":"李四","address":"xx省xx市xx区b街道","phone":"13668745577"}
]