0
Aoba, what is it? I’m trying to make a delete in my backend be called in HTML when a person clicks on a certain button. Then I’m passing a src script, to the file that has this Function. And in onclick I’m calling this Function, like this:
const db = require('../backend/db')
const routes = require('./routes')
const ideas = db.run('SELECT * FROM ideas')
function deleteIdeia(id) {
routes.delete(`/ideias/${id}`)
}
module.exports = deleteIdeia
and the onclick:
<button onclick="deleteIdeia(ideas.id)" />
And delete it on my back:
delete(req, res) {
const { id } = req.params
db.run(`DELETE FROM ideas WHERE id = ?`, [id], function (err) {
if (err) return console.log(err)
console.log('DELETEI')
})
return res.redirect('/ideias')
}
The problem is that he says that the deleteIdeia function has not been defined. If anyone can help me I thank you!
PS: The function of the backend is working well, I tested it in INSOMNIA.
How you are generating this html?
– Daniel Mendes
With html even. A file . html
– Henrique Sathler
Then you imported a js in the default Node in html?
– Daniel Mendes
That, exactly.
– Henrique Sathler
Checks if your console generates an error when you load the page.
– Daniel Mendes
No error appears in any
– Henrique Sathler