[英]Create table with jQuery - append in javaScript
您好,我試圖從注冊或更新學生的表單中添加記錄,但是它不起作用。 可能是什么原因? 這是我的嘗試:
<table id="allStudent" class="table table-bordered">
<thead>
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>studentCode</th>
<th>Major</th>
<th>FatherName</th>
<th>Action</th>
</tr>
</thead>
<script id="script" type="text/template">
<tbody id="body">
<%--<c:forEach items="${list}" var="student">--%>
<tr >
<td>
${firstName}
<%--<c:out value="${student.firstName}"/>--%>
</td>
<td>
${lastName}
</td>
<td>
${studentCode}
</td>
<td>
${major}
</td>
<td>
${fatherName}
</td>
<td>
<a href="" class="btn btn-success" role="button"><i class="fa fa-pencil"
style="padding-right: 10px;"></i>
Update </a>
<button onclick="" class="btn btn-danger" role="button"><i class="fa fa-trash"
style="padding-right: 10px;"></i>Delete
</button>
<a href="" class="btn btn-info" role="button"><i class="fa fa-check"
style="padding-right: 10px;"></i>Course
Selection
</a>
</td>
</tr>
</tbody>
</script>
並且我使用帶有ajax的模板jQuery來附加數據,每次注冊后我都可以在表上看到它:
var d = {data: JSON.stringify(dataToPost)};
console.log(dataToPost);
$.ajax({
type: "POST",
dataType: "json",
ContentType: "application/json",
url: "student?method=saveOrUpdate",
data: d,
success: function (data) {
all();
},
error: function (data) {
alert("error occured");
}
});
});
});
function all()
{
$.ajax({
type: "POST",
dataType: "json",
ContentType: "application/json",
url: "student?method=findAll",
success: function (data) {
$("#script").tmpl(data).appendTo("#body");
var ht = data.msg;
$("#resp").html(ht);
},
error: function (data) {
alert("error occured");
}
});
我解決了。 我應該放
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="true" %> in page
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.