您好,我试图从注册或更新学生的表单中添加记录,但它不起作用。 可能是什么原因? 这是我尝试过的:
<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>
我使用模板 jQuery 和 ajax 来附加数据,每次注册时我都可以在表格上看到它:
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
关于javascript - 使用 jQuery 创建表 - 在 javaScript 中追加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50781295/