Cybercrux

Everything is achievable through technology

csv file read

Fiddle

Html

<input type=”file” name=”filename” id=”filename”>
<div />

 

jquery

$(“#filename”).change(function(e) {
var ext = $(“input#filename”).val().split(“.”).pop().toLowerCase();
if($.inArray(ext, [“csv”]) == -1) {
alert(‘Upload CSV’);
return false;
}
if (e.target.files != undefined) {
var reader = new FileReader();
reader.onload = function(e) {
var lines = e.target.result.split(‘\r\n’);
for (i = 0; i < lines.length; ++i)
{
$(‘div’).append(‘<br>’ + lines[i]);
}
};
reader.readAsText(e.target.files.item(0));
}
return false;
});

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s