Javascript 来自数据库查询的AJAX请求为空

Javascript 来自数据库查询的AJAX请求为空,javascript,ajax,node.js,sqlite,Javascript,Ajax,Node.js,Sqlite,我正在发出一个AJAX请求,以便从SQLite中的DB(已经填充)中获取信息。给定以下代码: response.writeHead(200, {"Content-Type": "application/json; charset=UTF-8"}); var query = "SELECT * FROM Info"; var data = {}; var JSONf; db.all(query, function(err, rows

我正在发出一个AJAX请求,以便从SQLite中的DB(已经填充)中获取信息。给定以下代码:

 response.writeHead(200, {"Content-Type": "application/json; charset=UTF-8"});
        var query = "SELECT * FROM Info";
        var data = {};
        var JSONf;
        db.all(query, function(err, rows) {
            JSONf = rows;
            data['info'] = JSONf;
            console.log(JSON.stringify(data));
            response.end(JSON.stringify(data));
        });

        //response.end(data); // returns {}
        break;
当我做一个

console.log(xhr.responseText); 
在我的主javascript文件中,它只是空的。为什么信息发送不正确

编辑:

AJAX功能:

xhr.onreadystatechange = function(){ 
if(xhr.readyState === 4){
  if(xhr.status == 200 && xhr.status < 300)
  {
    console.log(xhr.responseText);


  }
}
};

xhr.open('GET', 'http://' + window.location.host + '/info', true);
xhr.send();
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
如果(xhr.status==200&&xhr.status<300)
{
console.log(xhr.responseText);
}
}
};
xhr.open('GET','http://'+window.location.host+'/info',true);
xhr.send();

如果在回调中
console.log(err)
会发生什么?@ppajer我得到nullwell。。。您还没有包括ajax调用。。我们猜猜你在里面写了什么?注意:您可以使用一个三方库(如jQuery)来测试问题是在ajax调用本身还是来自您的server@ymz编辑OP以包含呼叫。hhmmm…您有可能在服务器上出错吗?您没有检查代码中的err变量。。。也许查询本身失败了。。。。