This is my first project with nodejs, and probably I am asking something trivial. I hava a table to display list of items, that can be filtered in between two date. The table has a link to edit and a form button to delete.
When I click to edit a line, I move to the editing page, I perform my actions and when I go back to the filtered page this is reloaded. I follow answer 2 of this question, how to force page refresh on browser back click?
My problem is that I cannot achieve the same result with the delete form. I tried res.redirect('back'); and res.redirect(req.get('referer')); Can I be pointed to the right direction ?
Thanks Alb
app.search('/search', function(req, res) {
var sdate = req.body.sdate
var edate = req.body.edate
var sdate_full = req.body.sdate+' 00:00:00'
var edate_full = req.body.edate+' 24:59:59'
console.log("post received: %s %s", sdate, edate);
console.log("post received: %s %s", sdate_full, edate_full);
req.getConnection(function(error, conn) {
conn.query("SELECT * FROM item WHERE item_INSERT_DATE >= ? AND item_INSERT_DATE <= ?", [sdate_full, edate_full], function(err, rows) {
if (err) {
req.flash('error', err)
res.render('user/list', {
moment: moment,
title: 'Items',
data: ''
})
} else {
res.render('user/list', {
moment: moment,
title: 'Items',
data: rows
})
}
})
})
})
app.delete('/delete/(:id)', function(req, res, next) {
var user = { item_ID: req.params.id }
req.getConnection(function(error, conn) {
conn.query('DELETE FROM table WHERE item_ID = ' + req.params.id, user, function(err, result) {
if (err) {
req.flash('error', err)
res.redirect('/')
} else {
req.flash('success', 'Item deleted ! id = ' + req.params.id)
res.redirect(??????)
}
})
})
})
The form I start from is '/search', which filter my table list. The problem is that I can only redirect to '/' (which gives me the entire list), but not the search page updated with the line deleted. This is the last tiny bit to end this little job.