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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值