我想创建一个jQuery网格,它从json文件中获取数据,在Firefox中做的很好。但不会对谷歌Chrome浏览器 我从 trirand examples谷歌浏览器 - 没有访问控制允许源标头存在于请求的资源
这样我给的代码来获得JSON数据
jQuery("#rowed2").jqGrid({
url:'datagrid_data.json',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
pager: '#prowed2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#rowed2").jqGrid('navGrid','#prowed2',{edit:false,add:false,del:false});
谢谢@Patrick Gunderson。我没有在服务器上运行这个文件。我使用静态html和jquery(例如:http://trirand.com/blog/jqgrid/jqgrid.html#)。它在Firefox上正常工作。但不能在chrome中工作 – ess
您是通过file://访问文件的吗?这将解释为什么FF和铬的表现不同。一旦尊重本地文件的CORS,另一个不是 –
ys ...我通过file访问文件:/// – ess