0

I have googled for a long time, but have been unable to find the answer to the following question:

Code so far (within larger html file):

    var filename = "/Users/FlorisHolstege/Documents/data_weather/"
    var request = new XMLHttpRequest();
    file = request.open('GET', filename, true); 

I have csv file in my directory ("data_weather"). I want to read this file as an array, but I do not know how to access the content of the file.

Once I can access the content of the file, I can play around and turn it into an array. But currently I am unable to get anything from the file. Console.log(file) results in "undefined".

Any help would be great!

PA.
  • 28,486
  • 9
  • 71
  • 95
  • Don't post a picture of your code. Post the code. – Scott Marcus Nov 09 '17 at 16:12
  • Possible duplicate of [How to return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) + reading from a local directory doesn't work via web. – Teemu Nov 09 '17 at 16:14
  • Even I am sailing on the same boat. Searched the web for a long time, but still not knowing how to do. Document readystate is not matching. Could oyu please share your answer how you have solved it – Priya Nov 24 '22 at 16:29

1 Answers1

3

Try using query:

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "file url",
        dataType: "text",
        success: function(data) {console.log(data);}
     });
});
Jonas0000
  • 1,085
  • 1
  • 12
  • 36