jqgrid:无法显示json数据 [英] jqgrid: can't display json data
问题描述
我正在尝试在jqgrid中显示json数据,但没有任何行.
I'm trying to display json data in a jqgrid and I don't get any row.
这是我的网格:
$('#jqList').jqGrid({
url: '/my/url',
datatype: 'json',
colNames:['field1', 'field2'],
colModel:[
{name:'field1',index:'field1', width:200},
{name:'field2',index:'field2', width:300}
],
pager: '#jqPager',
rowNum: 20,
rowList: [10, 20, 30, 50],
height: '100%',
viewrecords: true,
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; },
id: 'id'
}
});
我可以在浏览器中访问我的网址,它显示如下内容:
I can access my url in my browser and it displays something like this :
{"rows": [
{"id": "3", "field1": "blabla", "field2": "blabla"},
{"id": "10", "field1": "blabla", "field2": "blabla"},
{"id": "4", "field1": "blabla", "field2": "blabla"},
{"id": "8", "field1": "blabla", "field2": "blabla"}
]
}
但是当我显示网格时,我没有任何数据. 如果我检查控制台,则我的网址上出现500错误(在网址中添加了一些参数)
But when I display my grid, I don't have any data as I said. If I check the console, I have a 500 error on my url (with some params added to the url)
希望我能提供足够的信息.
I hope I gave enough informations.
修改 Firebug控制台说:
edit firebug console says :
"NetworkError: 500 Internal Server Error - http://localhost/path/to/my/url?_search=false&nd=1373439192511&rows=20&page=1&sidx=&sord=asc"
我在apache服务器上使用PHP
I'm using PHP on apache server
php代码:
header('Content-type: application/json');
foreach ($cars as $k => $v) {
$tab['rows'][$k] = $v['Car'];
}
echo json_encode($tab);
谢谢
推荐答案
尽管我给了url : path/to/my/url
,但jqGrid似乎在等待这样的URL:path/to/my/json/url
在开发服务器上...并且url : path/to/my/url
在beta服务器上工作正常...
It seems that jqGrid was waiting a url like that : path/to/my/json/url despite I gave url : path/to/my/url
on the development server... and url : path/to/my/url
works fine on the beta server...
我真的不明白为什么,如果网址错误",为什么错误不是404?
I don't really understand why, if the url was "wrong" why the error wasn't 404 ?
无论如何现在都可以正常工作...
Anyway it's working fine now...
感谢您的时间
这篇关于jqgrid:无法显示json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!