我想創建一個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