In my code, I use javascript to send data to python(flask) and delete the button when it is successful. the code of the button is given below
The result is that it sends the data to python and the backend function on python is work but the button is not be deleted. I write alert(p) in the success:function because I want to know whether the function is used or not and it alerts!!. I am really new to HTML and javascript. Please someone explain how it works and tell me how to solve it!
$(document).on('submit', '#todo-form2', function(e) {
console.log('hello');
e.preventDefault();
$.ajax({
type: 'POST',
url: '/delete',
data: {
todo: $("#todo").val()
},
success: function() {
var p = $("#todo").val()
alert(p);
var elem = document.getElementByName(p);
elem.parentNode.removeChild(elem);
}
})
});
<form method="post" id="todo-form">
<button class="primary" name="560510531" id="todo" type="submit" value=560510531>
Accept
</button>
</form>
<form method="post" id="todo-form2">
<button class="primary ghost" name="560510531" id="todo" type="submit" value=560510531>
Deny
</button>
</form>