js与ajax动态添加表格,并避免重复添加
<html>
<head>
<title> New Document </title>
<SCRIPT LANGUAGE="JavaScript">
function test()
{
var html='<table id="tableId"><tr><th>AAA</th><th>BBB</th><th>CCC</th></tr>'
$.ajax({
type: 'POST',
url: '$path/test!show.do',
dataType:'JSON',
success:function(data)
{
$("#tableId").remove();
data=eval(data);
for(var i=0;i<data.length;i++)
{
var aaa=data[i].aaa;
var bbb=data[i].bbb;
var ccc=data[i].ccc;
html +='<tr><td>aaa</td><td >bbb</td><td >ccc</td></tr>'
}
html += '</table>';
$("#before_table").after(html);
}
});
}
</SCRIPT>
</head>
<body>
<input type="button" value="onclick" onclick="test();"/>
<input type="hidden" id="before_table">
</body>
</html>