一、在上一篇基础上。
把testajax.jsp改在如下
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="/springmvc/resources/css/css.css" rel="stylesheet">
<script type="text/javascript" src="/springmvc/resources/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
type:"post",
url:"/springmvc/test/testjson",
datatype:"json",
success:function(data){
for(var i=0;i<data.length;i++)
{
var tr=$("<tr id=del"+data[i].uid+"></tr>");
var td1=$("<td>"+data[i].uid+"</td>");
var td2=$("<td>"+data[i].uname+"</td>");
var td3=$("<td>"+data[i].upwd+"</td>");
var td4=$("<td><a href='javascript:del("+data[i].uid+")'>删除</a></td>");
tr.append(td1);
tr.append(td2);
tr.append(td3);
tr.append(td4);
$("#table").append(tr);
console.log($("#table").html());
}
}
});
});
function del(id)
{
console.log(id);
$("#table #del"+id).remove();
}
</script>
</head>
<body>
<table id="table" class="cssTable">
<tr>
<td>编号1</td>
<td>姓名</td>
<td>密码</td>
</tr>
</table>
</body>
</html>