Node.js passing parameters to client via express render

后端 未结 4 428
温柔的废话
温柔的废话 2020-12-03 11:49

I\'m using Node.js and I\'m having issues communicating with a client.

I define Express:

var express             = require(\"express\");
var app              


        
4条回答
  •  执笔经年
    2020-12-03 12:16

    The variable name you sent to the render function is only available while rendering the page, after it is sent to the client, it is not accessible. You have to use it in your view on the rendering stage.

    Since you are using handlebars, you can display it in your page like this, for instance:

    {{ name }}

    If you want to use this data in a javascript, use it inside a script tag:

    
    

提交回复
热议问题