Floris Holstege
Floris Holstege

Reputation: 59

How to read a CSV file from directory in Javascript?

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!

Upvotes: 0

Views: 3881

Answers (1)

Jonas0000
Jonas0000

Reputation: 1113

Try using query:

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

Upvotes: 3

Related Questions