I am trying to extract data from a CSV with JavaScript and then put these values into an array and display it. My csv will have multiple rows (5 or more). So far i am trying to use a jquery library to help extract the data. I couldn't get the script to display anything when I ran it. I am new to Javascript so wasn't sure how to do this and how to take the extracted data and put it into an array.
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title> Testing Orders</title>
</head> <body>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "tester excel.csv",
dataType: "text",
success: function(data) {processData(data);}
});
});
function processData(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var headers = allTextLines[0].split(',');
var lines = [];
for (var i=1; i<allTextLines.length; i++) {
var data = allTextLines[i].split(',');
if (data.length === headers.length) {
var tarr = [];
for (var j=0; j<headers.length; j++) {
tarr.push(headers[j]+":"+data[j]);
}
lines.push(tarr);
}
}
// alert(lines);
// console.log("tester excel.txt");
}
function getData() {
if (data == ""){
return 'DataNotReady';
}else {
}
}
windows.prompt(processData);
</script>
</body>
</html>`