我得到了我想要的结果,当我按下按钮时,它会删除我不想要的整个表格。
这是我的jQuery
$(document).ready(function() {
$('#button1').click(function(event) {
$('#list').empty();
$.ajax({
url : 'http://98.199.64.63/api/eric_api.php?q=series',
type : 'GET',
dataType : 'json',
success : function(data) {
var table = $("#list");
//table.html('');
$.each(data, function(idx, elem) {
table.append("<tr><td>" + elem.id + "</td>" + "<td>" + elem.user +
"</td>" + "<td>" + elem.email + "</td>" + "<td>" + elem.summary + "</td>" +
"<td>" + elem.due_date + "</td>" + "<td>" + elem.problem_type + "</td>"+
"<td>" + elem.status + "</td></tr>");
});
},
error : function() {
alert('There was an error');
}
});
});
});
这是我的html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="js/jquery.js"></script>
<script src="js/api_calls.js"></script>
<link rel="stylesheet" href="css/normalizer.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div>
<table id="list">
<tr>
<th>ID</th>
<th>User</th>
<th>Email</th>
<th>Summary</th>
<th>Due Date</th>
<th>Problem Type</th>
<th>Status</th>
</tr>
</table>
</div>
<div>
<button id="button1">Get Data</button>
</div>
</body>
</html>
我只想刷新 td 标签中的数据,而不是 th 标签。任何帮助谢谢