0

I am building like local html file to process csv log data and visualise that data using chart.js. This html file will always be used offline.

But at the first hurdle I can't seem get a success on the ajax request for the local csv file.

file:///Users/joshmoto/Sites/charts-app/data/LOG-01.csv

100% the csv file exists in this local location. If I right click 'open link in new tab via my console log, it automatically downloads the csv so it's definitely here. Theoretically my code below should not be returning an error response.

$.ajax({
    url: "//Users/joshmoto/Sites/chart/data/LOG-01.csv",
    dataType: "text",
    success: function(data) {

        alert("worked");

    },
    error: function (request, status, error) {

        alert("broken");

    }
});

I've also tried data type POST and GET but still always alerts me the error message.

Any ideas in where I'm going wrong would be hugely appreciated.

joshmoto
  • 4,472
  • 1
  • 26
  • 45
  • Possible duplicate. Please see the below thread- https://stackoverflow.com/questions/12546353/ajax-function-is-not-reading-csv-file-in-chrome – Ashique Oct 20 '19 at 20:12

1 Answers1

1

You cannot request the file as your browser is blocking the request due to security reasons. Unfortunately you have to run local server to access files or install plugin to allow cross origin requests (D3.js - load csv file from chrome) or you can run your browser with security measures turned off (for chrome How to launch html using Chrome at "--allow-file-access-from-files" mode?)