3

I am trying to create a jquery grid which gets data from a json file.it is doing fine in Firefox. but doesn't work on Google chrome i am doing this from trirand examples

i am giving the code to get json data

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});
ess
  • 663
  • 3
  • 9
  • 17

2 Answers2

1

If I understand correctly your problem: you can't access the local files per Ajax requests in Google Chrome. It's by design so. If you do need to change the behavior you have to start Chrome.exe with additional parameter --allow-file-access-from-files (the '-' should be written twice):

Chrome.exe --allow-file-access-from-files

It's important that you have to close all currently running instances of Chrome.exe before. During such kind of starting the security feature, which you don't like, will be switch off and you will be able to access local files per Ajax.

The list of options of Chrome.exe is described here (see here too).

Oleg
  • 220,925
  • 34
  • 403
  • 798
0

Access Control Origin headers are set and read to control access to data in browsers across domains. It's a security concern.

Here you can't access JSON from a different domain than your script is running without a CORS (Cross Origin Request Sharing) header.

There are ways around this restriction.

Most common is to enable Access Control Origin headers on the server side. This server setting tells browsers that it's OK for them to use the JSON data freely, usually because it's not sensitive. http://enable-cors.org/

Another common method around CORS is to pass yoru data in JSONP format. This is another server-side fix that wraps the JSON data in a function to execute on the client side. What is JSONP all about?

Community
  • 1
  • 1
Patrick Gunderson
  • 3,263
  • 17
  • 28
  • thanks @Patrick Gunderson. i am not running this file on a server. i am using static html and jquery (ex: http://trirand.com/blog/jqgrid/jqgrid.html#) . It works fine on firefox. but not working in chrome – ess Jan 24 '14 at 06:21
  • Are you accessing the file via file://? That would explain why FF and chrome are behaving differently. Once respects CORS on local files and the other doesn't – Patrick Gunderson Jan 24 '14 at 07:36
  • ys...i access file via file:/// – ess Jan 24 '14 at 07:38
  • I bet if you put your file on a server (even a local one) it would be rejected by both FF and Chrome – Patrick Gunderson Jan 24 '14 at 07:52