2013-03-03 42 views
0

我在joomla(版本2.5.9)中编写使用jqgrid(version 4.4.4)的代码。这是我的代码,我发现jqgrid不能显示joomla json_encode的数据。但joomla中的no是OK。 如果jqgrid url:testjson.php没问题。为什么jqgrid无法从joomla获取json数据?

<?php 
    header('Cache-Control: no-cache, must-revalidate'); 
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
    header("Content-Type: application/json;charset=utf-8"); 
header('Content-Disposition,attachment;filename=”json.json”'); 
    $response=new stdClass(); 
    $response->page = 1; 
    $response->total = 1; 
    $response->records = 1; 
    $response->rows[0]['id']='1'; 
    $response->rows[0]['cell']=array("1","vlan"); 
    echo json_encode($response); 
? 

我得到JSON:{ “页面”:1, “总”:1, “记录”:1, “行”:[{ “ID”: “1”, “细胞”:” 1“,”vlan“]}]}和jqgrid工作正常。

当的jqGrid网址:?的index.php选项= com_sysconfig &视图= VLAN &任务= ajaxvlane.getvlanlist &格式=原始

在子控制器,在功能getvlanlist,这个代码是吹塑:

<?php 
header('Cache-Control: no-cache, must-revalidate'); 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header("Content-Type: application/json;charset=utf-8"); 
header('Content-Disposition,attachment;filename=”json.json”'); 
$response=new stdClass(); 
$response->page = 1; 
$response->total = 1; 
$response->records = 1; 
$response->rows[0]['id']='1'; 
$response->rows[0]['cell']=array("1","vlan"); 
echo json_encode($response); 
JFactory::getApplication()->close(); 
?> 

通过萤火虫我可以看到json:{“page”:1,“total”:1,“records”:1,“rows”:[{“id”:“1”,“cell”:[ “1”,“vlan”]}]}与testjson.php结果相同。

但jqgrid无法显示任何数据。

什么错误导致问题?谢谢。

顺便说一句,如果我使用joomla创建XML数据,jqgrid工作正常。

+0

我得到的答案是:因为代码编辑器是UTF8 BOM charaset.If使用没有BOM uft-8,那么它工作正常。 – user2129229 2013-03-04 09:42:53

回答

0

我得到的答案是:因为代码编辑器是UTF8 BOM charaset.If使用没有BOM uft-8,那么它工作正常。