json数据传到前台并解析展示成列表

    xiaoxiao2021-12-12  5

    因为某些原因,项目中突然需要做自己做个ajax异步获取数据后动态向表格中添加数据的页面,网上找了半天都没有 看到现成的,决定自己写个例子

    1、HTML页面

    <!doctype html> <html> <head> <meta charset="utf-8"> <title>文件柜取件列表</title> <script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="/js/ai/ai-lib.js"></script> </head> <body> <div class="main pusher"> <form class="form_style"> <div class="fields"> <div class="div_1"> <label for="lbl">取件标题</label> <input name="FileTitle" type="text" id="FileTitle"> </div> <div class="div_l"> <label>取件发文单位</label> <input name="comeDept" id="comeDept" placeholder="" type="text"> </div> <div class="div_l"> <label>投箱时间</label> <input type="text" maxlength="50" name="sendTime" id="sendTime" placeholder=""> </div> <div class="div_l"> <label>打印人单位</label> <input type="text" maxlength="50" name="printDept" id="printDept"> </div> <div> <label>打印人姓名</label> <input type="text" maxlength="50" name="printUser" id="printUser"> <input type="button" value="查询" id="btSearch" class="btn_search"/> </div> </div> </form> <div class="table-container"> <table class="ui nine column table celled table-result" id="table-result"> <thead> <tr> <th>hotelSeq</th> <th>文件标题</th> <th>条码编号</th> <th>发文单位</th> <th>紧急程度</th> <th>份数</th> <th>密级</th> <th>投箱时间</th> <th>备注</th> </tr> </thead> <tbody id="tbody-result"> </tbody> </table> </div> </div> </body> </html> 2、filebox-print.jsp

    $(function () { $('#btSearch').click(function () { var FileTitle= $('#FileTitle').val(); var comeDept= $('#comeDept').val(); var sendTime= $('#sendTime').val(); var printDept = $('#printDept').val(); var printUser=$('#printUser').val(); var tbody=window.document.getElementById("tbody-result"); $.ajax({ type: "post", dataType: "json", url: "<%=path%>/filebox/fileBox!getToDoFileBoxList.action", data: { FileTitle: FileTitle, comeDept: comeDept, sendTime: sendTime, printDept: printDept, printUser:printUser }, success: function (msg) { if (msg.ret) { var str = ""; var data = msg.data; for (i in data) { str += "<tr>" + "<td>" + data[i].fileTitle+ "</td>" + "<td>" + data[i].fileCode+ "</td>" + "<td>" + data[i].comeDept + "</td>" + "<td>" + data[i].fileEmerg+ "</td>" + "<td>" + data[i].alreadyCount+ "</td>" + "<td>" + data[i].fileSecret+ "</td>" + "<td>" + data[i].sendTime + "</td>" + "<td>" + data[i].remark+ "</td>" + "<td>" + data[i].fileboxId+ "</td>" + "</tr>"; } tbody.innerHTML = str; } }, error: function () { alert("查询失败") } }); }); });   做完之后感觉瞬间就踏实了不少,这个礼拜可以好好休息了。俺接触这个又学到了一点前台的知识了。
    转载请注明原文地址: https://ju.6miu.com/read-900191.html

    最新回复(0)