javascript - jqgrid 中没有使用 XML 加载数据

标签 javascript php jquery xml jqgrid

您能帮我解决这个不便吗?我查了又查,找不到这个错误的答案。

我的 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" }

参见thisthis

关于javascript - jqgrid 中没有使用 XML 加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24472560/

相关文章:

javascript - 动态移动 div 中的元素以适合的数学

javascript - 获取键为空字符串的对象属性的值

php - 如何在 Laravel 中合并来自 Eloquent 模型的两个查询的结果?

php - 使用 cURL 获取 JSON 响应

javascript - 使用 match(),但它不适用于字符串变量

javascript - LoopBack 自动迁移调用顺序

javascript - 如何在 Angular 模块中定义层次结构路由

php - DOMElement 似乎没有从 DOMNodeList 中删除

javascript - jquery .find 并附加 img 标签

javascript - 如何在 IBM Worklight 中重定向到同一页面但不同的 div/ View ?