Need Jquery to read CSV file on page load -


i found code reading csv table through file search input cannot figure out how make automatically read csv file on page load.

here code csv table googlecode.

  $(document).ready(function() { if(isapiavailable()) {   $('#files').bind('change', handlefileselect); } });  function isapiavailable() { // check various file api support. if (window.file && window.filereader && window.filelist && window.blob) {   // great success! file apis supported.   return true; } else {   // source: file api availability - http://caniuse.com/#feat=fileapi   // source: <output> availability - http://html5doctor.com/the-output-element/   document.writeln('the html5 apis used in form available in following browsers:<br />');   // 6.0 file api & 13.0 <output>   document.writeln(' - google chrome: 13.0 or later<br />');   // 3.6 file api & 6.0 <output>   document.writeln(' - mozilla firefox: 6.0 or later<br />');   // 10.0 file api & 10.0 <output>   document.writeln(' - internet explorer: not supported (partial support expected in 10.0)<br />');   // ? file api & 5.1 <output>   document.writeln(' - safari: not supported<br />');   // ? file api & 9.2 <output>   document.writeln(' - opera: not supported');   return false; }  }   function handlefileselect(evt) { var files = evt.target.files; // filelist object var file = files[0];  // read file metadata var output = ''     output += '<span style="font-weight:bold;">' + escape(file.name) + '</span><br />\n';     output += ' - filetype: ' + (file.type || 'n/a') + '<br />\n';     output += ' - filesize: ' + file.size + ' bytes<br />\n';     output += ' - lastmodified: ' + (file.lastmodifieddate ? file.lastmodifieddate.tolocaledatestring() : 'n/a') + '<br />\n';  // read file contents printtable(file);  // post results $('#list').append(output);  }   function printtable(file) { var reader = new filereader(); reader.readastext(file); reader.onload = function(event){   var csv = event.target.result;   var data = $.csv.toarrays(csv);   var html = '';   for(var row in data) {     html += '<tr>\r\n';     for(var item in data[row]) {       html += '<td>' + data[row][item] + '</td>\r\n';     }     html += '</tr>\r\n';   }   $('#contents').html(html); }; reader.onerror = function(){ alert('unable read ' + file.filename); }; } 

i think can't automatically load local files html, because of sandbox security concern.
otherwise, can image that, hacker create fishing websites auto upload local files server , retrieve sensitive data.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -