I am working on offfline database, but getting problem some time.
So i am thinking to read data by jQuery from client machine instead of IndexDB(offline database).
So is it possilbe to read csv file using jQuery?
Yes it is possible but only in browsers that support HTML5
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } table { border: 1px solid #ccc; } table th { background-color: #F7F7F7; color: #333; font-weight: bold; } table th, table td { padding: 5px; border-color: #ccc; } </style> </head> <body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#upload").bind("click", function () { var reader = new FileReader(); reader.onload = function (e) { var table = $("<table />"); var rows = e.target.result.split("\n"); for (var i = 0; i < rows.length; i++) { var row = $("<tr />"); var cells = rows[i].split(","); for (var j = 0; j < cells.length; j++) { var cell = $("<td />"); cell.html(cells[j]); row.append(cell); } table.append(row); } $("#dvCSV").html(''); $("#dvCSV").append(table); } reader.readAsText($("#fileUpload")[0].files[0]); }); }); </script> <input type="file" id="fileUpload" /> <input type="button" id="upload" value="Upload" /> <hr /> <div id="dvCSV"> </div> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.