How to save a files contents in Javascript/jQuery -
basically, want upload csv file via javascript or jquery.
i want try , without php involved.
i need use html upload form, , save it's contents multidimensional array or string.
i not need save uploaded file server, need save it's contents string stated.
i have looked far , wide online, yet involves php.
is possible javascript or jquery?
thanks in advance
this uses library wrote , released under gplv3 license: html5csv
the example below uploads csv file browser, available array of arrays.
the library supports various block operations, such make table, edit, plot, fit, call function, save in browser session storage or local storage.
html
choose csv file load application: <input id='foo' type='file'> <hr />
js (requires jquery , html5csv.js)
csv.begin('#foo'). table('output', {header:1, caption:'uploaded csv data'}). go();
here, go()
can take function callback (e,d)
, e contain error string or null, , d object may contain d.rows[0][0],...,d.rows[n-1][m-1]
n x m
matrix of data. row 0 may header row.
asynchronicity used, in fact enforced in places. beware ajax, code return subsequent line, , best read setting workflow of when previous step becomes ready.
saving/restoring
you can save data user's browser localstorage object .save('local/somekey').
somewhere in workflow, , data existing in array @ point stored in html5 local storage (perhaps compressed if include lzstring library documented), until browser user deletes it.
then in same page or page on same web site can data out csv.begin('local/somekey')...
using data
you should put code want use data function can fit either callbacks expected html5csv's call
or go
documented on html5csv site.
Comments
Post a Comment