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!

3
  • Don't post a picture of your code. Post the code. Commented Nov 9, 2017 at 16:12
  • Possible duplicate of How to return the response from an asynchronous call? + reading from a local directory doesn't work via web. Commented Nov 9, 2017 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 Commented Nov 24, 2022 at 16:29

1 Answer 1

3

Try using query:

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "file url",
        dataType: "text",
        success: function(data) {console.log(data);}
     });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.