javascript - JS $.get method file with path -


i want load *.csv file path wich user can choose. path get: c:\\users\\...

but $.get method can't read path. how path have like?

$.get(pathandfile, function (data) {... 

if wanted read csv data in javascript computer need instruct user select file (there no way around this, possible exception of virus). once user selected file can read , parse csv data small amount of javascript (demo)

with html:

<input type="file" id="file" name="file" /> <table id="rows"></table> 

and javascript:

var output = $('#rows'); $('#file').on('change', function(evt) {   var files = evt.target.files;   (var = 0, f; f = files[i]; i++) {     // process text files.     if (!f.type.match('text/.*')) {       alert('unsupported filetype:'+f.type);       continue;     }     var reader = new filereader();     reader.onloadend = function(evt) {       var rows, row, cols, col, html;       if (evt.target.readystate == filereader.done) {         output.empty();         rows = evt.target.result.match(/[^\r\n]+/g);         for(row = 0; row < rows.length; row++) {           cols = rows[row].split(',');           html = '<tr>';           for(col = 0; col < cols.length; col++) {             html += '<td>'+cols[col]+'</td>';           }           html += '</tr>';           output.append(html);         }       }     };     // read in text file     reader.readasbinarystring(f);   } }); 

you can generate html table contents of csv file (this based on this excellent site)


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -