使用Bootstrap table的時候無法獲取數(shù)據(jù),后臺已經(jīng)返回了數(shù)據(jù)但是表格里面老是顯示No matching records found
下面是我主頁的代碼
?<?php
include("../Database/connect.php");
include("nav.php");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/bootstrap-table.css">
<script src="../js/bootstrap-table.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12" >
<h1>Exception</h1>
<h1>學(xué)生管理系統(tǒng)</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="pannel panel-default">
<div class="panel-heading">
查詢
</div>
<div class="panel-body form-group" style="margin-bottom: 0px;">
<label class="col-sm-1 control-label" style="text-align: right;margin-top: 5px;">姓名:</label>
<div class="col-sm-2">
<input type="text" class="form-control" name="name" id="search_name" />
</div>
<div class="col-sm-1">
<button class="btn btn-primary" id="search_btn">查詢</button>
</div>
</div>
</div>
<table id="mytab" class="table table-hover"></table>
<div id="toolbar" class="btn-group pull-right" style="margin-right:20px;">
<button id="btn_edit" type="button" class="btn btn-default" style="display: none; border-radius: 0">
<span class="glyphicon glyphicon-pencil" aria-hidden="true" ></span>修改
</button>
<button id="btn_delete" type="button" class="btn btn-default" style="display: none;">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>刪除
</button>
<button id="btn_add" type="button" class="btn btn-default">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
</button>
</div>
</div>
</div>
</div>
<script>
$(window).resize(function(){
$('#mytab').bootstrapTable('resetView'),{
height:tableHeight()
}
})
$('#mytab').bootstrapTable({
method: 'get',
contentType: "application/x-www-form-urlencoded",//必須要有?。。?!
url:"../data/tsconfig.json",//要請求數(shù)據(jù)的文件路徑
dataType:'json',
height:tableHeight(),//高度調(diào)整
toolbar: '#toolbar',//指定工具欄
striped: true, //是否顯示行間隔色
dataField: "res",//bootstrap table 可以前端分頁也可以后端分頁,這里
//我們使用的是后端分頁,后端分頁時需返回含有total:總記錄數(shù),這個鍵值好像是固定的
//rows: 記錄集合 鍵值可以修改 dataField 自己定義成自己想要的就好
pageNumber: 1, //初始化加載第一頁,默認第一頁
pagination:true,//是否分頁
queryParamsType:'limit',//查詢參數(shù)組織方式
queryParams:queryParams,//請求服務(wù)器時所傳的參數(shù)
sidePagination:'server',//指定服務(wù)器端分頁
pageSize:10,//單頁記錄數(shù)
pageList:5,//分頁步進值
showRefresh:true,//刷新按鈕
showColumns:true,
clickToSelect: true,//是否啟用點擊選中行
toolbarAlign:'right',
buttonsAlign:'right',//按鈕對齊方式
toolbar:'#toolbar',//指定工作欄
columns:[
{
title:'全選',
field:'select',
//復(fù)選框
checkbox:true,
width:25,
align:'center',
valign:'middle'
},
{
title:'ID',
field:'address',
visible:false
},
{
title:'登錄名',
field:'gender',
sortable:true
},
{
title:'性別',
field:'id',
sortable:true
},
{
title:'手機號',
field:'name',
},
],
locale:'zh-CN',//中文支持,
responseHandler:function(res){
//在ajax獲取到數(shù)據(jù),渲染表格之前,修改數(shù)據(jù)源
return res;
}
})
//三個參數(shù),value代表該列的值
function operateFormatter(value,row,index){
if(value==2){
return '<i class="fa fa-lock" style="color:red"></i>'
}else if(value==1){
return '<i class="fa fa-unlock" style="color:green"></i>'
}else{
return '數(shù)據(jù)錯誤'
}
}
//請求服務(wù)數(shù)據(jù)時所傳參數(shù)
function queryParams(params){
return{
//每頁多少條數(shù)據(jù)
// pageSize: params.limit,
//請求第幾頁
// pageIndex:params.pageNumber,
// Name:$('#search_name').val(),
// Tel:$('#search_tel').val()
}
}
//查詢按鈕事件
$('#search_btn').click(function(){
$('#mytab').bootstrapTable('refresh', {url: '../index.php/admin/index/userManagement'});
})
//tableHeight函數(shù)
function tableHeight(){
//可以根據(jù)自己頁面情況進行調(diào)整
return $(window).height() -280;
}
</script>
</body>
</html>
下面是我json文件的代碼
{
"total": 10,
"rows": [
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
},
{
"id": 0,
"name": "Item 0",
"gender": "$0",
"address":"廣東省"
}
]
}
就這樣很苦惱,Chrome已經(jīng)返回了數(shù)據(jù)了,但是table里面就一直報錯
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務(wù)負責iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。