entonces, acabo de aprender a hacer un sitio web con matraz. todo estaba bien hasta que este error me vuelve loco. ¿puedes resolver mi problema?
esta es mi función def para eliminar alguna nota
@views.route('/delete-note',methods=['POST']) def delete_note(): note = json.loads(request.data) noteId = note['noteId'] note = Note.query.get(noteId) if note: if note.user_id == current_user.id: db.session.delete(noteId) db.session.commit() return jsonify({})y este es mi codigo .js
function deleteNote(noteId) { fetch("/delete-note", { method: "POST", body: JSON.stringify({ noteId: noteId }), }).then((_res) => { window.location.href = "/"; }); }y así es como hago el botón con html
<ul class="list-group list-group-flush" id="notes"> {% for note in user.notes %} <li class="list-group-item"> {{ note.data }} <button type="button" class="close" onClick="deleteNote({{ note.id }})"> <span aria-hidden="true">×</span> </button> </li> {% endfor %} </ul>¿Puedes ayudarme? no se como solucionarlo por favor, ayúdame
¿Estás cargando el archivo js correctamente? Puede intentar cargar la función antes del marcado HTML, por ejemplo
<head> <script> function deleteNote(noteId) { fetch("/delete-note", { method: "POST", body: JSON.stringify({ noteId: noteId }), }).then((_res) => { window.location.href = "/"; }); }</script> </head> <body> <ul class="list-group list-group-flush" id="notes"> {% for note in user.notes %} <li class="list-group-item"> {{ note.data }} <button type="button" class="close" onClick="deleteNote({{ note.id }})"> <span aria-hidden="true">×</span> </button> </li> {% endfor %} </ul> </body>