Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用XML在jqgrid中不加载数据_Javascript_Php_Jquery_Xml_Jqgrid - Fatal编程技术网

Javascript 使用XML在jqgrid中不加载数据

Javascript 使用XML在jqgrid中不加载数据,javascript,php,jquery,xml,jqgrid,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

你能帮我解决这个不方便的问题吗。我检查了又检查,找不到这个错误的答案

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