loading sqlite database in javascript with sql.js
<p>Can someone provide a simple complete example of loading an existing sqlite database not using node.js.</p>

<p>Assume that the sql db is sitting in same location as index.html</p>

<p>example:</p>








<p>I tried this example but "contents" is undefined. Also, I would not know how to access the data in "contents"? I could really use a complete example. </p>

<pre><code>var xhr = new XMLHttpRequest();
xhr.open('GET', '/path/to/database.sqlite', true);
xhr.responseType = 'arraybuffer';

xhr.onload = function(e) {
  var uInt8Array = new Uint8Array(this.response);
  var db = new SQL.Database(uInt8Array);
  var contents = db.exec("SELECT * FROM my_table");
  // contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]
};
xhr.send();
</code></pre>