I am trying to load a local csv file to html table.When I load the html file in chrome I am unable to view the contents.The console says "navigated to file:///D:/report.html".There is no error message.
$(document).ready(function() {
$.ajax({
type: "GET",
url: "file:///D:/results.csv",
success: function(data) {
processData(data);
}
});
});
function processData(allText) {
var record_num = 2;
var allTextLines = allText.split(/\r\n|\n/);
var entries = allTextLines[0].split(',');
var lines = [];
var headings = entries.splice(0, record_num);
while (entries.length > 0) {
var tarr = [];
for (var j = 0; j < record_num; j++) {
tarr.push(headings[j] + ":" + entries.shift());
}
lines.push(tarr);
}
var output = [],
i;
for (i = 0; i < lines.length; i++)
output.push("<tr><td>" +
lines[i].slice(0, -1).split(",").join("</td><td>") +
"</td></tr>");
output = "<table>" + output.join("") + "</table>";
var div = document.getElementById('container');
div.innerHTML = output;
}
table {
border-collapse: collapse;
border: 2px black solid;
font: 12px sans-serif;
align-content: center;
}
td {
border: 1px black solid;
padding: 5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id='container'></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</body>
</html>
I can't find where I made the mistake. Thanks in advance.