0
我正在嘗試向API服務器發出https.request。我可以接收該塊(JSON)並將其打印在控制檯中。我如何直接將它寫入html並在瀏覽器中顯示?正文中的JSON請求html
var requestListener = function (req, res) {
var db = admin.database();
var ref = db.ref("Clubs");
ref.on("value", function(snapshot) {
console.log(snapshot.val()); //print on console
res.write(snapshot.val()); // in body html, error throw er;
// Unhandled 'error' event ^Error: write after end
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
// CRUD
ref.child("club1").set({
clubId: 1,
clubName: "club1",
telephone: "6548798",
address: "Lviv",
party: "qwe,asd,zxc"
});
ref.child("club2").set({
clubId: 2,
clubName: "club2",
telephone: "234234",
address: "Kiev",
party: "qwe,zxc"
});
res.end();
};
var server = http.createServer(requestListener);
server.listen(8080);
您必須對JSON進行串聯 –