admin管理员组文章数量:1414605
In PHP I used to pass objects from the backend to the front end in JSON form, using script tags.
<script>
var serversideStuff = '<?php echo json_encode($serversideArray); ?>';
</script>
How can I pass JS objects from the server-side to the clientside using nodeJS, express and Jade. There is probably a really good way that I'm just not aware of.
Hope you can help me out.
In PHP I used to pass objects from the backend to the front end in JSON form, using script tags.
<script>
var serversideStuff = '<?php echo json_encode($serversideArray); ?>';
</script>
How can I pass JS objects from the server-side to the clientside using nodeJS, express and Jade. There is probably a really good way that I'm just not aware of.
Hope you can help me out.
Share Improve this question asked Oct 6, 2011 at 17:04 wilsonpagewilsonpage 17.6k23 gold badges105 silver badges150 bronze badges 02 Answers
Reset to default 5In PHP you use bad practices (dynamically generating javascript as part of an application).
With node you do it right. This means you
- Either write the data to the HTML (How would your website work without javascript, you are using progressive enhancement, right?)
- Expose that data as a web service you talk to over Ajax or WebSockets
<script type="text/javascript">
var clientVar = {{JSON.stringify(serverVar)}}
</script>
change {{}} to whatever your template engine uses to interpret code
本文标签: javascriptHow can I pass JS objects from the serverside to the clientside in NodeJSStack Overflow
版权声明:本文标题:javascript - How can I pass JS objects from the server-side to the clientside in NodeJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744655129a2617919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论