【问题标题】:jqgrid dosnt show data,it's work fine in localhost but not in my serverjqgrid 不显示数据,它在 localhost 中运行良好,但在我的服务器中运行良好
【发布时间】: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; 看起来很可疑。除非在页面上方的另一个 &lt;script&gt;...&lt;/script&gt; 中定义了 $userId,否则它将引发错误。还是应该是var id = &lt;%php echo $userId; %&gt;;
  • 感谢您的响应..我没有复制这段代码的顶部......实际上这个脚本在一个php代码之间并用echo执行......你知道..例如:脚本>"; ?> 和 userid 定义在顶部,在 php 文件中 ....这段代码在我的本地主机中工作正常......但我不知道为什么在服务器中不起作用......
  • 我同意,这是个谜。可能是网址路径?服务器上的目录结构是否正确反映了 localhost 上的结构?

标签: php javascript jquery json jqgrid


【解决方案1】:

我几乎可以肯定 url 值不正确。 url 通过 Ajax 调用返回 JSON 数据。过去调试并不容易……直到有 Firebug。

在 Firefox 中使用 Firebug(按 F12)并单击“控制台”选项卡,然后刷新您的页面。查看 Console 中返回的数据。如果它不是有效的 JSON 或 404 错误,那么您知道下一步该做什么。

我只知道如何在 Firefox 中执行此操作,在 Google Chrome 或 IE 开发人员工具栏中找不到等价物。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 2018-02-09
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    相关资源
    最近更新 更多