简体   繁体   中英

Create table with jQuery - append in javaScript

Hi I was trying to add records from form that register or update student, but it is not working. What might be the reason? here is what I am tried:

               <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>

and I use template jQuery with ajax to append data that with every registration I can see it on table:

      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");
    }
});

I solve it . i should put

<%@ page contentType="text/html;charset=UTF-8" language="java"    isELIgnored="true" %> in page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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