node.js - Passing Variable from NodeJS to client-side JS file -


is possible pass server-side javascript variable <script> tag in html view?

in routes file have:

exports.index = function(req, res){   res.sendfile('views/index.html', {       data: {foo: bar}   }); }; 

if using jade template, do:

script(type='text/javascript').   var local_data =!{json.stringify(data)} 

to access data object. however, doesn't work html file. there work-around this?

have route send data using res.json() , use ajax in html fetch json data.

http://www.w3schools.com/ajax/


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -