The code below is working fine. It will grab my data from a CSV file and read each line one at a time and display it in 15 second intervals. Now it working perfect. Someone suggested to me that maybe instead of waiting 15 seconds for the new data to appear.. to just display all the data at once but scroll in a loop the information.
Instead of a per line display I’m trying to get all lines to display. I’m not sure how to go about doing this..Using the console.log I am able to print all lines in the processCsvData function.. But I get stuck there and don’t know how to passes all the fields of every line at once.
So if I have lets say 5 lines of data.. it will display:
data[0][1] data[0][2] data[0][4] data[0][5]
data[1][1] data[1][2] data[1][4] data[1][5]
data[2][1] data[2][2] data[2][4] data[2][5]
data[3][1] data[3][2] data[3][4] data[3][5]
data[4][1] data[4][2] data[4][4] data[4][5]
The CSV file will always need to display field 1, 2, 4, and 5 per line. The number of lines sometimes change.
Any help will be appreciated. Not sure why im having a hard time getting this to work.
using these JS files: jquery and jquery csv
Currently its
[CODE]
function pullCsv() {
var csvData;
csvData = $.ajax({
type: “GET”,
url: “test.CSV”,
dataType: “text”,
cache: false,
success: function (result) {
csvResult = result;
if (csvResult == “”) {
noCsvData();
} else {
processCsvData(csvResult);
}
}
});
};
function processCsvData(csvResult) {
var data = $.csv.toArrays(csvResult);
for (var i = 0; i < data.length; i++) {
printEvents(data, i);
}
setTimeout(function () {
pullCsv();
}, 15000 * data.length);
}
function printEvents(data, idx) {
setTimeout(function () {
document.getElementById(“line1”).innerHTML = data[idx][1];
document.getElementById(“line2”).innerHTML = data[idx][2];
document.getElementById(“line3”).innerHTML = data[idx][4];
document.getElementById(“line4”).innerHTML = data[idx][5];
}, idx * 15000);
}