【发布时间】:2012-12-25 12:25:18
【问题描述】:
我在 php 中遇到了 jqgrid 的问题,首先我应该说,在我的 localhost 中一切正常,一切正常,但在我的服务器中却没有 jqgrid不显示数据,我检查了php文件和js文件,js向php发送数据,php正确选择了我需要的数据,但是发生了一些事情,php文件没有错误,并正确填写$response,然后echo json_encode ($response);.....我想问题就在这里,当 php 文件想要将数据发送到脚本时......我真的不知道......请帮助我......有代码 js文件:
<script type='text/javascript'>
jQuery('document').ready(function() {
var id = $userId;
jQuery('#users').jqGrid({
url:'../includes/ProductHistory/process.php?id='+id,
datatype: 'json',
mtype: 'GET',
direction:'rtl',
height: 'auto',
width: '530',
colNames:['pic ','pname','pdate', 'price'],
colModel:[
{name:'file_url',index:'file_url', width:40 , sortable:false , search:false , edittype: 'image', formatter: imageFormatter},
{name:'product_name',index:'product_name', width:65},
{name:'created_on',index:'created_on', width:70 ,search:false},
{name:'product_final_price',index:'product_final_price', width:60 , sorttype:'number'}
],
rowNum:10,
rowTotal: 2000,
rowList : [10,20,30,50],
rownumbers: true,
rownumWidth: 15,
gridview: true,
pager: '#usersPage',
sortname: 'created_on',
viewrecords: true,
sortorder: 'desc',
caption: 'products'
});
jQuery('#users').jqGrid('navGrid','#usersPage',
{
edit:false,add:false,del:false,search:false,refresh:true
},
{}, // edit options
{}, // add options
{}, //del options
{} // search options
);
jQuery('#users').jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
});
function imageFormatter(cellvalue, options, rowObject) {
return '<img src= ../' + cellvalue + ' height=80 width=80 />';
};
</script>
这是 php 文件:
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$response->rows[$i]['product_name'] = $row['product_name'];
$response->rows[$i]['cell'] = array($row['file_url'],$row['product_name'],$row['created_on'],$row['product_final_price']);
$i++;}
echo json_encode($response);
我检查了 sql 查询,我用 fwrite 复制到一个 txt 文件中,它工作正常...但我不知道为什么 jqgrid 不显示任何内容,它显示列和名称但它不支持单元格... ..........请帮帮我....我真的不知道我该怎么办....
【问题讨论】:
-
脚本顶部的
var id = $userId;看起来很可疑。除非在页面上方的另一个<script>...</script>中定义了 $userId,否则它将引发错误。还是应该是var id = <%php echo $userId; %>;? -
感谢您的响应..我没有复制这段代码的顶部......实际上这个脚本在一个php代码之间并用echo执行......你知道..例如:脚本>"; ?> 和 userid 定义在顶部,在 php 文件中 ....这段代码在我的本地主机中工作正常......但我不知道为什么在服务器中不起作用......
-
我同意,这是个谜。可能是网址路径?服务器上的目录结构是否正确反映了 localhost 上的结构?
标签: php javascript jquery json jqgrid