I have a json data in a controller file and I got this data from an API so that I can be able to redirect this data gotten from the API to an ejs file but when I write the code in the body tag part like this <%-JSON.stringify(jsonData)%>, it will display the entire JSON but when I am using this statement under script tags I don't get anything but [object object] error message is what comes out.
How can I use this JSON data inside script tags for displaying each and every key/value pair from the JSON data? Can you anyone suggest an answer?
In Controller:
res.render('display', {
jsonData: storeJSONData
});
I wrote this code for a redirecting template.
No talk just watch :P
I have send data like this.
res.render('studentlist',{'studentlist' : result} );
Then I show those data in a table like this baby :D
<table class="table table-inverse">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<% for(var i=0; i < studentlist.length; i++) { %>
<tr>
<td><%= studentlist[i].name %></td>
<td><%= studentlist[i].email %></td>
<td><%= studentlist[i].username %></td>
</tr>
<% } %>
</tbody>
</table>
I hope it will help you out there. I am pretty sure . :) Thank you very much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With