How to pass variables in node js?
How to pass variables in node js?
Here I'm passing id which stored in m, please help me how to pass id. and call that page using that id. I'm using the embedded JavaScript template as a view engine please help.
id
m
id
id
$.each(products, function(index, product )
var m= product['_id'];
//document.write(alert(m));
string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="/profile/dashboard/update/m">Update</a> </td></tr>';
);
route code
app.get('/profile/dashboard/update/:m',function (req,res,next)
console.log("hi"+req.params.m);
);
When i click on upadte button id is not passing in the url which is the major concern here'
– EasyFreeNotes
Sep 3 at 9:41
3 Answers
3
string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="profile/dashboard/update/'+id+'">Update</a> </td></tr>';
It will work
You need to use this quotes `` for template string;
as example:
var m = 1;
var string = `id: $m`
Not working sir
– EasyFreeNotes
Sep 3 at 9:35
`... <a href=/profile/dashboard/update/$product['id']>Update</a> </td></tr>`
`... <a href=/profile/dashboard/update/$product['id']>Update</a> </td></tr>`
You need to wrap your whole string in backticks and pass the variables as written above ( $var_name ). See this answer for more info. This isn't a NodeJS question, more of a Javascript question itself.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please explain more what you want exactly, as of now your code seems to be good.
– Gaurav joshi
Sep 3 at 9:19