您能帮我解决这个不便吗?我查了又查,找不到这个错误的答案。
我的 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>
知道为什么我的网格没有加载任何数据吗?
谢谢。
最佳答案
关于javascript - jqgrid 中没有使用 XML 加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24472560/