空网格使用Jquery 1.5.2返回到JQgrid 4.1.1

时间:2011-07-03 23:13:21

标签: jquery json jqgrid

我很难在网格中显示数据。 查询可用于通过firstname,lastname或'serialnumber'

来重新计算数据

HTML看起来像

    <script src="lib/jquery/jquery-1.5.2.min.js" type="text/javascript" ></script>
     <script src="lib/jquery/jquery-ui.min.js" type="text/javascript"> </script>
    <script src="lib/jqgrid/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="lib/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script>
    <div id="search">
     <table id="list"></table>
     <div id="pager" ></div>
       </div>

数据库和PHP现在是LOCAL,MYSQLi查询每次都会获得正确的数据。

Javascript看起来像

$('#list').jqGrid({
url:'http://localhost/ajax-search.php',
datatype: 'json',
postData: {
user: function() { return jQuery("input#username").val(); },
pass: function() { return jQuery("input#password").val(); },
firstname: function() { return jQuery("#firstname_label").val(); },
lastname: function() { return jQuery("#lastname_label").val(); },
number: function() { return jQuery("#number_label").val(); }
},
mtype: 'POST',
colNames:['id','First','Last', 'Number'],
colModel:[
{name: 'id',  index:'id',width:10,hidden:false},
{name: 'targetfirstname',  index:'targetfirstname',width:25},
{name: 'targetlastname',   index:'targetlastname',width:25},
{name: 'number',       index:'number', width:25},
],
rowNum:10,
width:340,
height: 25,
setGridHeight:45,
shrinkToFit:true,
rowList:[10,20,30],
imgpath: 'lib/jquery/themes/base/images',
pager: $('#pager'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"Edit records",
});

PHP / MYSQL(正在使用的准备状态)看起来像

$response = new stdClass();
$response->page =      $page;           // current page
$response->total =     $total_pages;    // total pages
$response->records =   $numrows;        // total records
                $stmt2->execute()
                || fail('MySQL execute', $db->error);
                $stmt2 -> bind_result($seltargetfirstname,$seltargetlastname,$selnumber )
                || fail('MySQL bind_result', $db->error);

$i=0;
while($row = $stmt2->fetch()) {
  fwrite($fh2,"\n I is $i \n");
  $response->rows[$i]['id']=$i;
  $response->rows[$i]['cell']=array($i,$seltargetfirstname,$seltargetlastname,$selnumber);
  $i++;
  fwrite($fh2, "\nTO ENCODER $i $seltargetfirstname $seltargetlastname $selnumber\n");
}

echo json_encode($response);

我看到的是

[1] NO Apache/PHP/JSON encode or MYSQL  errors
[2] I can write out the returned MYSQLI fetch values to a file, all look good
[3] I generate a row number as I dont use/need these in my schema
[4] The grid generates in JQGRID and I can sort and see my query re-execute but  NO data
    in the grid at all..

任何想法都赞赏......

1 个答案:

答案 0 :(得分:0)

使用firebug的网络控制台(适用于Firefox),同时启动请求以查看是否从服务器获取json。 告诉我们之后会发生什么。

希望这会有所帮助。干杯