I get that A in ajax is asynchronous. But I can't find an alternatives to what i'm trying to do. I have a graph that I need to feed with a javascript array. This array is made from a csv import. So I'm trying to make a function that return an array with the function recupCSV():
data = [];
objet function (data, objet) {
var jour = data[3].split("/");
var start = new Date(jour[2], jour[1], jour[0]);
var dtS = new Date(start.getFullYear(), start.getMonth(), start.getDate());
jour = data[4].split("/");
var end = new Date(jour[2], jour[1], jour[0]);
var dt = new Date(end.getFullYear(), end.getMonth(), end.getDate());
var workItem = {id: data[0],name: data[1],lane: data[2],start: dtS,end: dt ,desc: data[5]};
objet.push(workItem);
}
function recupCSV(data) {
donnee = [];
$.ajax({
url: "http://www.example.com/csvfile.csv",
aync: false,
success: function (csvd) {
csv_as_array = $.csv2Array(csvd);
for(var i in csv_as_array )
objet(csv_as_array[i],data);
},
dataType: "text",
complete: function () {
}
});
return data;
}
I can see many reasons why it doesn't work, but I can't see any that would.. ;)