bootstrap table onLoadError加载服务端数据失败事件

bootstrap table onLoadError加载服务端数据失败时执行的事件,返回status, jqXHR对象。

onLoadError事件

加载服务器端数据失败时的事件,返回参数如下。

参数名称说明
statushttp状态 如 404 ,500
jqXHRXMLHTTPRequest object对象

绑定onLoadError事件方法一

$('#table').bootstrapTable({
    columns: columns, //列对象
    data: data, //要显示的数据对象
    onLoadError: function (status, jqXHR) {
       alert(JSON.stringify(status));  
    }
});

绑定onLoadError事件方法二

$('#table').on('load-error.bs.table', function (e,status, jqXHR) {
      alert(JSON.stringify(status));
});


完整代码

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="https://www.itxst.com/package/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
    <link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
    <link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
    <script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>
    <title>Bootstrap Table onLoadError例子</title>
    <style>
        .table-demo {
            width: 80%;
            margin: 30px auto 0px auto;
        }
        .fixed-table-header {
            border-right: solid 1px #ddd;
            border-top: solid 1px #ddd;
        }
            .fixed-table-header table  {
                border-top: solid 0px #ddd !important;
                margin-top:-1px;
            }
    </style>
</head>
<body >
    <div>
        <table id="table"></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [{
            field: 'Id',
            title: '编号'
        }, {
            field: 'ProductName',
            title: '名称'
        }, {
            field: 'StockNum',
            title: '库存'
        }];
 
        //bootstrap table初始化数据
        $('#table').bootstrapTable({
          columns: columns,
          classes: "table table-bordered table-striped table-sm ", //设置表格样式
           height:400,
          //******服务器端分页设置****
           url: "/package/bootstrap-table-1.14.1/111data.json", //服务器返回数据的网址
           method: 'GET',   //数据请求方式
           sidePagination:'server',
           search:true, //******开启搜索框****//
           searchOnEnterKey:false, //******回车后执行搜索****//
           pagination:true,
           pageNumber:1,
           pageSize:2,
           pageList:"[10, 20, 50, 200]",
           paginationHAlign:"left",
           paginationDetailHAlign:"right",
           //******服务器端分页设置****
          onLoadError: function (status, jqXHR) {
             alert(JSON.stringify(status));  
           }
        });
      
     // $('#table').on('load-error.bs.table', function (e,status, jqXHR) {
     // alert(JSON.stringify(status));
    //  });
    </script>
</body>
</html>

在线试一试