前端开发-Bootstrap-table定时更新

版权声明:本文为博主精心打造,转载请标明出处。>_< https://blog.csdn.net/slyslyme/article/details/82845287
var app = {};
    app.timeTicket = setInterval(function(){
       
        $.ajax({
            type : 'POST',
            url : "/",
            dataType:"json",
            data:{'host': host_ip},
            success : function (msg) {
                $('#table').bootstrapTable('removeAll');
                $('#table').bootstrapTable('load', msg);
            },
            error:function(msg){
                alert("table-error");
            }
        });
    },2000);

<!--表格-->
    function getData_table(){
        $("#table").bootstrapTable({
        ajax:ajaxReqDate,
        striped: true,
        pagination: true,                   //是否显示分页(*)
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        search: true,                      //是否显示表格搜索
        pageNumber: 1,                      //初始化加载第一页,默认第一页,并记录
        strictSearch: true,
        showColumns: true,                  //是否显示所有的列(选择显示的列)
        showRefresh: true,                  //是否显示刷新按钮
        minimumCountColumns: 1,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        columns : [
            {
                field: 'username',
                title: '用户名'
            }, {
                field: 'intercept',
                title: '日志类型'
            }, 
                ···
                ···
            ],
    });
    }
    function ajaxReqDate(result){
            console.log(result);
            $.ajax({
            type : 'POST',
            url : "/",
            contentType: "application/json;charset=utf-8",
            dataType:"json",
            data:{'host': host_ip},
            success : function (msg) {
                result.success({
                    row:msg
                });
                $('#table').bootstrapTable('removeAll');
                $('#table').bootstrapTable('load', msg);
            },
            error:function(msg){
                alert("table_error");
            }
        });
    }

要注意的是每次都要清除数据然后加载新的数据,不然数据只在界面第一次加载时从后台获取数据。

猜你喜欢

转载自blog.csdn.net/slyslyme/article/details/82845287
今日推荐