使用 twbs 分页插件通过 ajax 更新 smarty 变量

Update smarty variable via ajax using twbs Pagination plugin

我正在使用 twbs 分页插件,每次点击页码时,都会触发 ajax 调用,每页获取 10 个结果。 在页面上传时,获取前 10 个结果并将其分配给 smarty 变量。

这是tpl文件。我将从 php 获取的数组分配给变量 batchesData 并使用 foreach 循环对其进行迭代以以表格形式显示它

 <table class="table table-striped projects tablesorter" 
  id="batchTable" style="font-size: 13px;">
 <th>
 .....
 .....
 </th>
 <tbody>
 {if !empty($batchesData)}
 {foreach from = $batchesData key = filter item = value}
 <tr>
 ......
 ......
 </tr>
 {/foreach}
  </tbody>
 </table>

现在点击页面,这是我的 js 代码,我可以根据 php 的页面编号获取数组,但是我该如何更新它,因为我猜聪明的执行是在 ajax 来电。请推荐

    $(function () {
        window.pagObj = $('#pagination').twbsPagination({
            totalPages: 35,
            visiblePages: 10,
            onPageClick: function (event, page) {
                $.ajax({
                    type : 'POST',
                    url : '/mbatch/batch/listBatch',
                    data : {
                        page: page,
                    },
                    beforeSend : function() {

                    },
                    success : function(response) {
                    /* Handling */
                    },
                    error : function(data) {
                        new PNotify({
                            title: 'Notice',
                            text: JSON.parse(data.responseText).message,
                            type: 'error',
                            styling: 'bootstrap3'
                        }); 
                    }
                });
            }
        }).on('page', function (event, page) {
        });
    });

任何线索将不胜感激。这是插件 link http://www.jqueryscript.net/demo/Simple-Customizable-Pagination-Plugin-with-jQuery-Bootstrap-Twbs-Pagination/

试试这个:

     $(function () {
    window.pagObj = $('#pagination').twbsPagination({
        totalPages: 35,
        visiblePages: 10,
        onPageClick: function (event, page) {
            $.ajax({
                type : 'POST',
                url : '/mbatch/batch/listBatch',
                data : {
                    page: page,
                },
                beforeSend : function() {

                },
                success : function(response) {
                $("#batchTable").empty();//clearing the current table rows
                var dataRes=JSON.parse(response);
                var resultCount=dataRes.length; //Assuming result set in array form.
                //now creating row for each result set and appending to table
                $.each(dataRes,function(index,value){
                $("#batchTable").append("<tr>
               <td>"+
              value.item1+" 
              </td>
              <td>"+
              value.item2+"
              </td>
               </tr>")
                })
                },
                error : function(data) {
                    new PNotify({
                        title: 'Notice',
                        text: JSON.parse(data.responseText).message,
                        type: 'error',
                        styling: 'bootstrap3'
                    }); 
                }
            });
        }
    }).on('page', function (event, page) {
    });
});

假设您的回复将采用 json 格式。在 success 函数

中相应地设置格式