GomezAddamz
Technical User
Hiya! I wrote a simple JavaScript to parse a CSV file into an HTML table. Works great in FF (23), not so much in IE (8) or Chrome (35). It seems like the XMLHttpRequest is gumming up the works. IE will create the request, but doesn't seem to want to open it. Chrome will open it, but chokes when it tries to send. I've hit the web, and it seems like the code should be the same for each browser, so I'm not sure what I'm doing wrong. I'd appreciate it if you could take a look and hopefully point me in the right direction. Thanks!
JavaScript:
<html>
<head>
<title>
Supplies
</title>
<style>
table, td {
text-align: center;
border-collapse: collapse;
border: 1px solid black;
}
</style>
<script type="text/javascript">
function initialize() {
request = new XMLHttpRequest();
alert("Request!");
request.open('GET','Supplies.csv',false);
alert("Open!"); //IE fails here
request.send();
alert("Sent!"); //Chrome fails here
rows = request.responseText.split("\n");
for (i = 0; i < rows.length; i++) {
trow = "<tr>";
tdata = rows[i].split(",");
for (j = 0; j < tdata.length; j++){
trow = trow + "<td>" + tdata[j] + "</td>";
}
document.getElementById('table1').innerHTML = document.getElementById('table1').innerHTML + trow + "</tr>";
}
}
</script>
</head>
<body onload="initialize()">
<table id='table1'></table>
</body>
</html>