Loading CSV file with AlaSQL and JQuery

£可爱£侵袭症+ 提交于 2019-12-13 15:32:33

问题


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:

  1. I can't find documentation for what alasql expects in the [event] slot.
  2. How does the FROM FILE method relate to the more specific FROM CSV and FROM XLSX methods.
  3. 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.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!