【问题标题】:how to send a json object from index.js to html in node.js如何将 json 对象从 index.js 发送到 node.js 中的 html
【发布时间】:2015-02-03 06:15:10
【问题描述】:

我通过调用 RESTFUL Web 服务在 index.js(node.js) 中获取 json 数据

index.js:
===========
    var options = {
        host: '192.168.7.54',
        port:8080,
        path:'/restful/traffic/upload',
        method:'POST',
         headers: {
            'Content-Type': 'application/json',
        }
    };

    var req = http.request(options, function(res) {
        res.setEncoding('utf-8');


        res.on('data', function(d) {
            dbdata = [d];
            console.log(dbdata);
        });
    });

这里的 dbdata 是从 webservice 返回的 json 对象。这里,我想将此 dbdata 重定向到另一个 html 文件(包含 d3 饼图)并使用此 dbdata 来显示饼图。我现在该怎么做。可以任何人请就这个问题提出建议...

【问题讨论】:

  • 请在这个问题上给我建议
  • 与其从 RESTAPI 获取数据到 nodejs 服务器然后将数据发送到客户端,为什么不简单地使用 ajax 客户端呢?

标签: javascript json node.js d3.js


【解决方案1】:

如果您使用的是 expressJS,那么您必须在渲染模板时传递它。 如果没有,那么您将必须在此处构建完整的 HTML 并将其传递给 res.end();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 2018-01-09
    • 2019-03-11
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多