不使用XML在jqgrid中加载数据
No data loading in jqgrid using XML
你能帮我解决这个麻烦吗?我查了又查,还是找不到这个错误的答案。
我的jqgrid没有加载信息,我不知道为什么。
这是我的jqgrid代码jQuery().ready(function(){
jQuery("#list").jqGrid({
sortable: true,
url: "service.php?username='$active_user'",
datatype: "xml",
mtype: "GET",
colNames: ["ID Donation", "Amount", "Institution", "Country of Institution", "Document ID", "Date"],
colModel: [
{ name: "id_donation", index:"id_donation",width: 55 },
{ name: "total", index:"total", width: 90 },
{ name: "institution", index:"institution",width: 80, align: "right" },
{ name: "country_institution", index:"country_institution",width: 80, align: "right" },
{ name: "id_personal_doc", index:"id_personal_doc",width: 80, align: "right" },
{ name: "donation_date", index:"donation_date",width: 80, sortable: true }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "donation_date",
rownumbers: true,
sortorder: "desc",
viewrecords: true,
gridview: true,
caption: "Your past donations",
height: 230,
width:800
});
这是我的service。php
<?php
include("Connections/db.php");
$username = $_GET['username'];
$page = $_GET['page'];
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
// sorting order - at first time sortorder
$sord = $_GET['sord'];
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;
// connect to the MySQL database server
$db = mysql_connect($hostname_db, $username_db, $password_db) or die("Connection Error: " . mysql_error());
// select the database
mysql_select_db($database_db) or die("Error connecting to db.");
// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM aedonatio01.donation");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit*$page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
// the actual query for the grid data
$SQL = "SELECT id_donation, username, total, institution, country_institution, id_personal_doc, donation_date FROM aedonatio01.donation WHERE username = $username ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
// we should set the appropriate header information. Do not forget this.
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=iso-8859-15");
} else {
header("Content-type: text/xml;charset=iso-8859-15");
}
$et = ">";
$s = "<?xml version='1.0' encoding='iso-8859-15'?".$et."'n";
$s .= "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row[id_donation]."'>";
$s .= "<cell>". $row[id_donation]."</cell>";
$s .= "<cell>". $row[total]."</cell>";
$s .= "<cell>". $row[institution]."</cell>";
$s .= "<cell>". $row[country_institution]."</cell>";
$s .= "<cell>". $row[id_personal_doc]."</cell>";
$s .= "<cell>". $row[donation_date]."</cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
?>
这是我的XML
<rows>
<page/>
<total>0</total>
<records>2</records>
<row id="1ses">
<cell>1ses</cell>
<cell>500</cell>
<cell>Escuela de Desarrollo Cultural</cell>
<cell>El Salvador</cell>
<cell>033316600</cell>
<cell>26/06/2014</cell>
</row>
<row id="334d">
<cell>334d</cell>
<cell>340</cell>
<cell>Casa de la Salud</cell>
<cell>El Salvador</cell>
<cell>033316600</cell>
<cell>15/05/2014</cell>
</row>
</rows>
知道为什么我的网格没有加载任何数据吗?
谢谢。
您需要使用XML阅读器
xmlReader: { repeatitems: false, root:"rows",row:"row" }
参见this and this
相关文章:
- 正在等待呈现图表,直到加载数据为止
- ng绑定和ng href问题.ng href未从控制器加载数据
- 单击按钮时加载数据
- 在reactjs组件中预加载数据
- Highcharts可以从服务器加载数据,但不能更新
- AngularJS promise在加载数据之前得到解决
- 在Knockout JS中搜索从DB加载数据的项目
- 如何在angular js中使用$emit后重新加载数据
- 构建多个图表时,HighCharts加载数据的速度较慢
- 加载初始网站后在后台加载数据
- ExtJS网格未从Ext.data.XmlStore加载数据
- 数据表 AJAX 筛选器重新加载数据
- select2 使用 AJAX 加载数据不能选择任何选项
- 在 Metro 风格应用中启动时加载数据
- 需要帮助使用 AJAX 和其他一些东西加载数据
- Vue 不加载数据
- 向右滚动加载数据
- 为SEO的数据绑定JS预加载数据
- mysql循环-预加载数据
- 无法使用JSON加载数据表