javascript - How can I pass JSON to client using Node.js + HBS + Express? -
consider, sending json client follows in render page of express (using hbs view engine):
res.render('mypage.html', { layout: false, pagetitle: 'project name', json_data: {field1:'value',field2:'value2'}});
i able access , set title of html page using {{pagetitle}}
, next code.
<title>{{pagetitle}}</title>
now want show json_data
alert popup.
i've tried next way, getting uncaught syntaxerror: unexpected token {
, while debugging in chrome shows var jsonobj = [object object]
function fbonbodyload() { var jsonobj = {{json_data}}; alert(jsonobj); }
could body give thought on how access json_data
, show in alert
advance thanks
you register handlebars helper format object string format (such using json.stringify), , utilize helper in view. http://handlebarsjs.com/block_helpers.html
javascript json node.js express handlebars.js
No comments:
Post a Comment