getting data from post
app.post("/places", function(req, res) {
//Get all places from the DB
Place.find({}, function(err, places) {
if(err) {
console.log(err);
} else {
res.render("/places", {places: places});
}
});
});
i want something like if(variable is passed then below code will work on same page) otherwise i face errors "undefined variable places" if i render to a new page, get that variable it works fine, but i want on same page
// ejs file
<div class="row text-center">
<% places.forEach(function(place) { %>
<div class="col-md-4 col-sm-6">
<div class="thumbnail">
<img src="<%= place.image %>">
<div class="caption">
<h5><strong><%= place.name %></strong></h5>
</div>
</div>
</div>
<% }); %>
</div>
Aucun commentaire:
Enregistrer un commentaire