我已经使用 node js express 从 facebook 获得了一系列 json 数据。现在我想将数据发送到 html 页面。但是我不知道如何发送数据以及如何在 html 中对数据进行编码。
最佳答案
如果你在 node.js 中使用 Express,这里是发送 json 对象作为响应的方式:
app.get('/test', function(req, res, next) {
res.json({ message: 'Hello World' });
});
然后在你的html页面html的JS中,如果你使用jQuery:
$.ajax({
url: '/test',
complete: function(data) {
console.log(data);
}
});
随意尝试一些东西,以及使用 Chrome 中的开发工具,实验 - 有助于理解它的工作原理和工作原理。
关于node.js - 如何从 Node js发送json数据到html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17365039/