I am trying to use a function to read csv file and return it. but unfortunately i got an empty string
function getStations() {
var final_results = [];
$.ajax({
type: "GET",
url: "CSV.csv",
dataType: "text",
success: function (data) {
var lines = data.split(/\r\n|\n/);
//Set up the data arrays
var stations_data = [];
//var headings = lines[0].split(','); // Splice up the first row to get the headings
for (var j = 1; j < lines.length; j++) {
var values = lines[j].split(','); // Split up the comma seperated values
// We read the key,1st, 2nd and 3rd rows
// tmp_data.push(parseFloat(values[0]));
//tmp_data.push(parseFloat(values[1]));
//tmp_data.push(parseFloat(values[2]));
//tmp_data.push(values[4]);
stations_data.push(values[4]);
final_results.push(values[4]);
}
console.log("inside:" + final_results.length)
}
});
// Let's process the data from the data file
console.log("outside: " + final_results.length);
}
the results is as following: console.log results
any suggestions?