0

所以我不断得到 [object Object] 查询结果的实际位置。我的问题是,我的回调是否不正确,因为我很难理解它,但认为我做对了。

HTML部分:

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

JS部分:

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();
}

我想补充一点,我的 IDE 告诉我,“SQL”没有声明为全局变量——不确定是否有问题,因为 sql.js 是在 html 文件中实现的。

4

0 回答 0