问题
I'm building an HTML based app for querying imported CSV file using AlaSQL. I started with this demo and tried to implement the same behavior by setting the onChange
event through JQuery rather than in the tag. I basically follow the same pattern, and naively pass the event forward to the loadFile
method. Alternatively, I tried just handling the alasql
request right in the callback.
html:
<input id="with-jquery" name="with-jquery" type="file" />
javascript:
$('#with-jquery').on('change', function(event)
{
console.log('in jquery callback');
filename = $('#with-jquery').val();
console.log("filename: " + filename);
alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(res){
console.log('in alasql callback');
data = res;
console.log(res);
document.getElementById("jquery-result").textContent = JSON.stringify(res);
});
//loadFile(event);
});
http://plnkr.co/edit/FOWwVsW7zAUGwv3BDBdN?p=preview
When I try to load the file using the JQuery handler, I get
in jquery callback
test.js:7 filename: C:\fakepath\sample.csv
alasql.min.js:13 Uncaught Error: Wrong usage of FILE() function
Here are some questions:
- I can't find documentation for what alasql expects in the
[event]
slot. - How does the
FROM FILE
method relate to the more specificFROM CSV
andFROM XLSX
methods. - The wiki shows using the
FROM CSV
method by supplying a file name. I can't imagine how that would work without supplying the full path to a local file. But you can't get that from the browser. - The wiki also recommends using the "promise" format. How would I implement that here?
来源:https://stackoverflow.com/questions/35838028/loading-csv-file-with-alasql-and-jquery