Reputation: 6559
In the node.js server, I sent a value in json format and need to put that in a javascript variable. I send the value like
res.render('/path/', {
testVal: 'testVal'
});
In the handlebars I can get it by
{{testVal}}
Now I want to get it in a javascript variable in the client side. Like in jQuery
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
var test = testVal;
alert(test);
}
}
How to get the testVal in the test variable?
Upvotes: 3
Views: 264
Reputation: 1501
Assuming that you are using jquery in the same file the data is rendered then you can do something like this :
<script>
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
var test = "{{ testVal }}";
alert(test);
}
}
</script>
Upvotes: 1