我是新来的nodejs
。这是我在nodejs
文件中的代码。我想将数据发送nodejs
给其他javascript
用途json.stringify
,但我的问题是我得到空值...... ----------------EDIT------------ ------------
我的代码是
function handler ( req, res ) {
calldb(dr,ke,function(data){
console.log(data); //successfully return value from calldb
});
//i think my problem bellow...
res.write( JSON.stringify(data)); //send data to other but it's null value
res.end('\n');
}
function calldb(Dr,Ke,callback){
// Doing the database query
query = connection.query("select id,user from tabel"),
datachat = []; // this array will contain the result of our db query
query
.on('error', function(err) {
console.log( err );
})
.on('result', function( user ) {
datachat.push( user );
})
.on('end',function(){
if(connectionsArray.length) {
jsonStringx = JSON.stringify( datachat );
callback(jsonStringx); //send result query to handler
}
});
}
如何解决这个问题?