1

I am building small offline web app using HTML and JavaScript. CSV file is used to store data.

To read CSV (using jquery-csv library) file I use following code.

<script>
    $(document).ready(function(){

        var filepath = 'data.csv';
        var data_string = $.get(filepath);
    });

</script>

But I can't read it because of following error.

XMLHttpRequest cannot load file:///C:/Users/Nimal/Desktop/javascript-csv/data.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

Then, I found many related articles from here.

  1. "Cross origin requests are only supported for HTTP." error when loading a local file
  2. XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP
  3. Ways to circumvent the same-origin policy

But I could not find a way to solve my problem. I don't want to use web server. How do I load that CSV file to get data without error(error mean same-origin policy issue)?

  • https://stackoverflow.com/questions/18586921/how-to-launch-html-using-chrome-at-allow-file-access-from-files-mode . Also, FireFox works with get XMLHttpRequests locally. – Teemu Sep 13 '17 at 08:48
  • @Teemu I am going to give this app for a few persons... So It is not possible to chnage their computers setting – I am the Most Stupid Person Sep 13 '17 at 08:51
  • 1
    Just adding a command to a short-cut path is not quite a "computer setting". Anyway, it's your only change with Chrome, unless you want to write a plug-in. Notice also what I've said about FF. – Teemu Sep 13 '17 at 08:54
  • Surprisingly MS Edge seems to allow local get XMLHttpRequests too. – Teemu Sep 13 '17 at 10:22

0 Answers0