繁体   English   中英

使用jQuery创建表-在JavaScript中追加

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM