jqGrid赢得';在Chrome中加载JSON数据时没有错误

jqGrid赢得';在Chrome中加载JSON数据时没有错误,json,google-chrome,jqgrid,Json,Google Chrome,Jqgrid,我有很多jqGrid的工作示例,昨天我添加了一个新的。它在我的本地主机上运行得很好,但是当我将它移动到我的在线登台服务器时,我会看到加载屏幕,然后什么也没有。没有错误 一些注释: 1) 使用JSON,一次下载所有内容 2) 在同一浏览器的localhost中工作正常。 3) HTML源看起来完全相同 4) JS源是相同的 5) JSON数据是相同的 6) 暂存服务器上的PHP5.1,本地服务器上的PHP5.3 7)适用于Firefox3(问题出现在Linux和Windows上的Chrome11上

我有很多jqGrid的工作示例,昨天我添加了一个新的。它在我的本地主机上运行得很好,但是当我将它移动到我的在线登台服务器时,我会看到加载屏幕,然后什么也没有。没有错误

一些注释:
1) 使用JSON,一次下载所有内容
2) 在同一浏览器的localhost中工作正常。
3) HTML源看起来完全相同
4) JS源是相同的
5) JSON数据是相同的
6) 暂存服务器上的PHP5.1,本地服务器上的PHP5.3
7)适用于Firefox3(问题出现在Linux和Windows上的Chrome11上)
8) 以前在我的其他jqGrid设置中从未遇到过这种情况

以前有人碰到过这样的事吗?这让我很困惑,我不想开始调试jqGrid本身

编辑: 以下是我的jqGrid调用:

jQuery(function(){
  jQuery('#list1').jqGrid({
    url:'/index.php?option=com_coinnet&view=snap&layout=list&Itemid=123&format=json&ajax=1',
    datatype: 'json',
    mtype: 'GET',
    colNames: ["ID","Date","Dealer","Amount","Check Number","Tracking Number","Deal Done","Note?","Date Sort"],
    colModel: [{"name":"id","width":0,"hidden":true,"key":true},{"name":"date_postedstr","width":100,"align":"right","index":"date_posted"},{"name":"stationlink","width":100,"align":"right"},{"name":"amount","width":120,"align":"right","sorttype":"float","formatter":"number","formatoptions":{"decimalSeparator":".","thousandsSeparator":",","decimalPlaces":2}},{"name":"check_number","width":100,"align":"right"},{"name":"tracking_number","width":100,"align":"right"},{"name":"status","width":50,"sortable":false,"align":"right","formatter":"checkbox","formatoptions":{"disabled":"false"}},{"name":"link","width":60,"align":"right","formatter":"showlink","formatoptions":{"idName":"dealID","baseLinkUrl":"","addParam":"&option=com_coinnet&view=snap&layout=deal&Itemid=124"}},{"name":"date_posted","hidden":true,"width":0}],
    pager: '#pager1',
    loadonce:true,
    rowNum:10,
    rowList:[5,10,20,25,30,50,100,-1],
    sortname: 'date_posted',
    sortorder: 'DESC',
    viewrecords: true,
    caption: 'SNAP Deals',
        multiselect:false,jsonReader : {
        root:"data",
        page: "currpage",
        total: "totalpages",
        records: "totalrecords",
        repeatitems: false,
        id: "0"
    },

    loadComplete: function() {
        jQuery("option[value=-1]").text('All');
    },
    height: 'auto',
    });
});
这是我的数据:

{"data":[{"id":"1654088","my_name":"CT00","my_id":"11920","other_name":"NV23","date_posted":"2010-12-07 14:23:34","check_number":null,"tracking_number":null,"notes":null,"shipped":"F","paid":"F","status":false,"amount":null,"check_number_date":null,"tracking_number_date":null,"newversion":"F","bulletin_id":null,"original_mailbox_id":null,"parcel_carrier_id":null,"date_postedstr":"12\/07\/2010","link":"Add","stationlink":"<a target='_blank'\n                href='?option=com_coinnet&view=dealerinfo&Itemid=122&station=NV23'>NV23<\/a>"},{"id":"1631050","my_name":"CT00","my_id":"11920","other_name":"FO81","date_posted":"2010-07-13 09:49:10","check_number":null,"tracking_number":null,"notes":null,"shipped":"F","paid":"F","status":false,"amount":null,"check_number_date":null,"tracking_number_date":null,"newversion":"F","bulletin_id":null,"original_mailbox_id":null,"parcel_carrier_id":null,"date_postedstr":"7\/13\/2010","link":"Add","stationlink":"<a target='_blank'\n                href='?option=com_coinnet&view=dealerinfo&Itemid=122&station=FO81'>FO81<\/a>"}],"totalrecords":75,"totalpages=>":8,"currpage":"1","userdata":null}
{“data”:[{“id”:“1654088”,“my_name”:“CT00”,“my_id”:“11920”,“other_name”:“NV23”,“date_posted”:“2010-12-07 14:23:34”,“check_number”:null,“tracking_number”:null,“notes”:null,“shipped”:“F”,“paid”:“F”,“status”:false,“amount”:null,“check_number_date”:null,“tracking_number_date”:null,“tracking_number”;“newversion_id”:null,“original_邮箱id”:null,“包裹承运商id”:空,“寄出日期”STR:“12\/07\/2010”,“链接”:“添加”,“站点链接”:“NV23”},{“id”:“1631050”,“我的姓名”:“CT00”,“我的id”:“11920”,“其他姓名”:“FO81”,“寄出日期”:“2010-07-13 09:49:10”,“支票号码”:空,“追踪号码”:空,“备注”:空,“发货”:“F”,“付款”:“F”,“状态”:假,“金额”:空,“支票号码”:空跟踪编号日期:null,“新版本”:“F”,“公告id”:null,“原始邮箱id”:null,“包裹承运人id”:null,“邮寄日期STR”:“7\/13\/2010”,“链接”:“Add”,“stationlink”:“FO81”}],“totalrecords”:75,“totalpages=>”:8,“currpage”:“1”,“userdata”:null}

我不确定您的主要问题是什么。您的代码和JSON数据有一些小错误,我建议您修复。您可以尝试修复版本。它在Chrome 11中工作

我修复的小问题的简短列表:

  • JSON数据包含
    “totalpages=>”:8
    而不是
    “totalpages”:8
    ,但由于使用
    loadonce:true
    参数,数据将被忽略
  • height:'auto'
    下面有一个尾随逗号。这是语法错误,某些浏览器可以忽略它(但在IE中不能)
  • 行列表中的值
    -1
    是错误的。您应该使用一些大整数。例如,您可以使用
    行列表:[5,10,20,25,30,5010010000]
    并将
    loadComplete
    中的代码固定到
    jQuery(#pager1选项[value=10000])。text('All');
  • 如果对某些网格列使用
    key:true
    jsonReader
    id
    属性将被忽略
  • 我建议您对所有隐藏列使用
    width:1
    (或任何其他正值),而不是
    width:0
  • colModel
    的包含不是JSON数据。它只是对象初始化。因此不需要双引号引用属性名称
  • 您可以删除jqGrid的所有默认参数,如
    multiselect:false
    mtype:'GET'
  • 不要使用long
    url
    参数
    url:'/index.php?option=com\u coinnet&view=snap&layout=list&Itemid=123&format=json&ajax=1'
    我建议您使用
    url:'/index.php'
    postData:{option:“com\u coinnet”,view:“snap”,layout:“list”,Itemid:123,format:“json”,ajax:1}
    。URL的构造将相同,但您可以确保,参数值内的特殊字符(包括空格等)将在需要时正确编码
以下是修改版本的代码:

jQuery('#list1').jqGrid({
    url:'LarrikJ.json', // 'index.php'
    postData: {
        option: "com_coinnet",
        view: "snap",
        layout: "list",
        Itemid: 123,
        format: "json",
        ajax: 1
    },
    datatype: 'json',
    colNames: ["ID","Date","Dealer","Amount","Check Number","Tracking Number",
               "Deal Done","Note?","Date Sort"],
    colModel: [
        {name:"id",width:1,hidden:true,key:true},
        {name:"date_postedstr",width:100,align:"right",index:"date_posted"},
        {name:"stationlink",width:100,align:"right"},
        {name:"amount",width:120,align:"right",sorttype:"float",formatter:"number",
         formatoptions:{decimalSeparator:".",thousandsSeparator:",",decimalPlaces:2}},
        {name:"check_number",width:100,align:"right"},
        {name:"tracking_number",width:100,align:"right"},
        {name:"status",width:50,sortable:false,align:"right",formatter:"checkbox",
         formatoptions:{disabled:"false"}},
        {name:"link",width:60,align:"right",formatter:"showlink",
         formatoptions:{idName:"dealID",baseLinkUrl:"",
         addParam:"&option=com_coinnet&view=snap&layout=deal&Itemid=124"}},
        {name:"date_posted",hidden:true,width:1}
    ],
    pager: '#pager1',
    loadonce: true,
    rowNum: 10,
    rowList: [5,10,20,25,30,50,100,10000],
    sortname: 'date_posted',
    sortorder: 'DESC',
    viewrecords: true,
    caption: 'SNAP Deals',
    jsonReader: {
        root: "data",
        page: "currpage",
        total: "totalpages",
        records: "totalrecords",
        repeatitems: false
    },

    loadComplete: function() {
        jQuery("#pager1 option[value=10000]").text('All');
    },
    height: 'auto'
});

我想出来了。答案就在这一行原来的问题中:

6)登台服务器上的PHP5.1,本地服务器上的PHP5.3

有一个无效字符(显示为�) 在数据库的一个字段中,该字段在PHP5.1中没有正确转义,但在PHP5.3中


我称之为Chrome bug,因为Firefox处理得很好,Chrome至少应该生成一个警告(它没有使页面崩溃,或使javascript崩溃,或任何类似的东西)。不过,jqGrid本身可能正在抑制警告。

非常感谢Oleg,您指出了我代码中的一些好缺陷。它们没有解决我的问题,但我确实设法解决了。