【问题标题】:Unable to load json data with jqgrid, although jsonstring works fine无法使用 jqgrid 加载 json 数据,尽管 jsonstring 工作正常
【发布时间】:2011-09-23 19:29:53
【问题描述】:

我有一个 jqgrid,我想用我的 json 填充它,但我无法让它工作。我认为我的 json 很好,因为在将 json 作为字符串(数据类型:jsonstring)提供时网格正在工作。问题是,我没有从 jqgrid 中得到任何错误,这使得调试变得困难。

这是我的 json(使用 jslint 验证):

{ "total":"1", "page":"1", "records":"5", "rows": [ {"id" :"1", "cell" :["Modulex", "", "", "", ""]}, {"id" :"2", "cell" :["Lemoltech", "", "", "", ""]}, {"id" :"3", "cell" :["Isothermic", "", "", "", ""]}, {"id" :"4", "cell" :["Renova", "", "", "", ""]}, {"id" :"5", "cell" :["Natart Juvenile", "", "", "", ""]} ] }

这是我的配置

$("#list").jqGrid({
    url:'/tempajax/',
    datatype: 'json',
    colNames:['Nom','Adresse','Ville','Tel','Courriel'],
    colModel :[ 
      {name:'company_name', index:'company_name', width:55}, 
      {name:'address', index:'address', width:90},
      {name:'city', index:'city', width:90},
      {name:'telephone', index:'telephone', width:80}, 
      {name:'email', index:'email', width:80}, 
    ],
    autowidth: true,
    pager: '#pager',
    rowNum:10,
    viewrecords: true,
    gridview: true,
    height: '100%'
});

这是我在这里的第一篇文章,所以我希望提供足够的信息来帮助你们,如果不仅仅是问的话。

非常感谢您的帮助!

【问题讨论】:

    标签: php jquery json jqgrid


    【解决方案1】:

    您的 JSON 结果与您配置要使用的 jqGrid 不匹配。

    您的 jqGrid 需要一个 JSON 结果,其中包含 company_name、address、city、telephone 和 email 作为字段,但您的数据带回 id 和单元格,即使这样,它也嵌套在顶部的 json 结果中,其中有总数,页、记录和行。无论哪种方式,它都没有与您的 jqGrid 对齐。

    【讨论】:

    • 感谢您的输入,但我担心这可能不是问题,因为当我在字符串变量(数据类型:jsonstring)中使用 JSON 输出时它可以工作。这是相同的 JSON,它可以工作,所以我认为问题出在 ajax 请求以检索 JSON。你怎么看?
    【解决方案2】:

    我解决了我的问题,毕竟 json 很好。即使输出很好,服务器也会抛出 404 代码。这甚至阻止了 jqGrid 解析 json。我希望这对其他人也有帮助!

    【讨论】:

      猜你喜欢
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 2013-12-14
      相关资源
      最近更新 更多