0

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.

whatever.idc
  • 92
  • 1
  • 1
  • 10
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Jun 24 '17 at 10:27
  • Yeah I already read through that all already, my question is if my callback is correct or if the problem is somewhere else to search - like suggested in the question. – whatever.idc Jun 24 '17 at 10:50

0 Answers0