<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!-- 引入通用的资源页面 -->
<jsp:include page="/page/common/res.jsp" />
<script>
$(document).ready(function() {
$.post("${ctx}/test.do", function(data, status) {
for (var i = 0; i < data.length; i++) {
alert("name:" + data[i].name + " age:" + data[i].age);
//此处获取到的值为:lin 24 ;
// zhang 23;
}
});
});
</script>
</head>
<body>
<table id="tt">
<tr>
<td>姓名:</td>
<td>年龄:</td>
</tr>
</table>
</body>
</html>
------ Solution ------------------------------------ --------
$.post("${ctx}/test.do", function(data, status) {
$("#tt).find("tr:gt(0)").remove();//把已有数据清除
for (var i = 0; i < data.length; i++) {
//alert("name:" + data[i].name + " age:" + data[i].age);
$("#tt).append("<tr><td>"+data[i].name+"</tr><td>"+data[i].age+"</td></tr>");//添加一行数据
}
});
------ For reference only ---------------------------------- -----
well, with the information I find online is the same, or give you scores ! !
没有评论:
发表评论