JavaScript sql.js - is callback correct?

62 Views Asked by At

So i keep getting [object Object] where actually the result of a query should be. My question is, whether my callback is incorrect, because I have a hard time understanding it, but think i did it correct.

HTML-part:

<button type="button" id="input_search" onclick="getSearchFromSQL()">Search</button>

JS-part:

function getSearchFromSQL() {
    document.getElementById('output').innerHTML = contents;
}

getSearchAsync(function (result) {

    contents = result;
});

function getSearchAsync(callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'test123.sqlite3', true);
    xhr.responseType = 'arraybuffer';

    xhr.onload = function (e) {
        var uInt8Array = new Uint8Array(this.response);
        db = new SQL.Database(uInt8Array);
        callback(db.exec("SELECT * FROM data"));
    };
    xhr.send();
}

I want to add, that my IDE tells me, that "SQL" is not declared as a global variable - not sure if there is a problem, since sql.js is implemented in the html-file.

0

There are 0 best solutions below