I need to select a csv file from local file system and display the contents of that file as text using jquery.
I am using this for file Upload
<input id = "uploadCSV" type = "file" />
On its change event,
$('#uploadCSV').change(function(e) {
if(e.target.files != undefined) {
var reader = new FileReader();
reader.onload = function(e) {
var lineSplit = e.target.result.split("\n");
var commaSplit = lineSplit[0].split(",");
var content = "";
for(var i = 0; i < commaSplit.length; i++) {
var temp = commaSplit[i];
content = content + " " + temp;
}
};
reader.readAsText(e.target.files.item(0));
var fileContent = reader.result;
alert(fileContent);
}
});
Somehow this doesn't work and I get null in alert when I use Firefox. If I use IE8, it crashes as it cannot locate e.target.result. Please advise
I am looking for the simplest way of converting a csv file in my local file system into plain text.
Thanks