Forum


18:21

07/07/2010

Hi all,
I've been trying to debug this for ages with no success, hopefully someone can point me in the right direction.
I'm trying to replicate one of the examples in the documentation but can't get it to work. Here's my client-code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DT.....tional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="includes/classes/jqgrid/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="includes/classes/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="includes/classes/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<link type="text/css" href="/sandbox/css/dark-hive/jquery-ui-1.8.custom.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" media="screen" href="includes/classes/jqgrid/css/ui.jqgrid.css" />
<style>
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script type="text/javascript">
jQuery().ready(function (){
jQuery("#list2").jqGrid({
url:'server.php?q=2',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<table id="list2"></table>
<div id="pager2"></div>
</body>
</html>
JSON data looks like this:
{"page":1,"total":100,"records":"1","rows":[{"id":"200","cell":["200","111","test","664.3","144","900","yay"]}]}
Any tips would be appreciated.
Thanks,
Wakie.
18:33

23/06/2010

I had a super hard time getting JSON data to populate... it ended up being the way that it was connecting to the database.
Assuming that your files are setup properly on the server (I made sure mine were by manually populating the data without any JSON or XML calls)... what I did was replace the "dbconfig.php" call with my own connection document, and then replace the "$db = " in my server.php file with my own connection item.
Any chance you could paste your entire server.php file? (excluding your login info, of course).
19:08

07/07/2010

Hi churd,
It's essentially a hacked up version of the demo PHP script, but here it is anyway:
$page = 1;//$_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect('localhost', 'root', '')
or die("Connection Error: " . mysql_error());
mysql_select_db('fone_site') or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = 100;//ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id";
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[id];
$responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
$i++;
}
echo json_encode($responce);
?>
Hello,
This may be a red herring, but I got burned on something similar to this today, until I found the following note in the jQuery site:
Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes.
I notice that not all of the data returned in your json string is enclosed in double quotes. You might wnat to try changing that to see if it makes any difference (even the numbers).
HTH
Reg
Most Users Ever Online: 715
Currently Online:
63 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66