在另一个页面上单击“后退”按钮时,如何保留带有jquery数据表内容的表单

时间:2019-05-06 02:13:56

标签: javascript jquery datatables thymeleaf

单击返回上一页上的按钮时,我无法加载上一个表单/页面。我想保留所有表单变量和数据表内容。我使用过history.go(-1),它保留下拉列表值,但不保留输入选择值。在单击ID配置文件页面时,将被调用。在个人资料页面上,返回按钮应指向所有内容的前一页。

下面是代码段:

<script> 
    //Generates datatable 
    function runReport() { 
        var $form = $("#" + $('#formName').val()); 
        $.ajax({ 
            url : '/events', 
            type : 'post', 
            data : $form.serialize(), 
            success : function(response) { 
                $('#sometable').DataTable({ 
                    "info": false, 
                    "paging": true, 
                    "ordering": true, 
                    "stateSave": true, 
                }); 
            } 
        }); 
    } 

    //Calls profile page of customer 
    function callProfilePage(id, custid) { 
        var datTable = $("#table").DataTable(); 
        var info = datTable.page.info(); 
        var pageindex=info.page; 
        var href = '/profile?custid='+custid+'&id='+id+'&pageindex='+pageindex; window.open(href,"_self"); 
    } 
</script>
<div> //Calls function to generate datatable content <button id="runreport" value="runreport" name="action" type="button" class="btn btn-primary" onclick="runReport()">Run Report</button>
</div>
<div class="col-sm-12 px-0" id="sometable"> //Datatable thats generated on click of Run Report <table class="table table-striped table-bordered table-sm" id="potential-tamper-table" cellspacing="0">
        <thead class="thead-light">
            <tr>
                <th scope="col">Report Date</th>
                <th scope="col">ID</th>
                <th scope="col">Customer ID</th>
                <th scope="col">Date of Event</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>30/04/2019</td>
                <td>
                    <a onclick="callProfilePage(id,custid)"/>86332</td> // Call to another page <td>
                    <span>12652666</span>
                </td>
                <td>
                    <span>31/10/2018 </span>
                </td>
            </tr>
        </tbody>
    </table>
</div>

0 个答案:

没有答案