google chrome--No Access-Control-Allow-Origin header is present on the requested resource

12,043

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).

Share:
12,043
ess
Author by

ess

Updated on June 05, 2022

Comments

  • ess
    ess almost 2 years

    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
    ess over 10 years
    thanks @Patrick Gunderson. i am not running this file on a server. i am using static html and jquery (ex: trirand.com/blog/jqgrid/jqgrid.html#) . It works fine on firefox. but not working in chrome
  • Patrick Gunderson
    Patrick Gunderson over 10 years
    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
  • ess
    ess over 10 years
    ys...i access file via file:///
  • Patrick Gunderson
    Patrick Gunderson over 10 years
    I bet if you put your file on a server (even a local one) it would be rejected by both FF and Chrome