I perform an ajax call that stores some data and adds a row in a table. In this row there is a delete button at the end so you are able to instantly delete the row you created if you want.
For some reason when I click the delete button I get redirected to the deleteurl of the ajax call I use to delete the data from the database. When I reload the page and press the delete button it works fine.
Anyone knows why this is happening?
The row that is being added:
<tr>
<td>test</td>
<td>
<form class="deleteBuildingForm" method="POST" action="http://127.0.0.1:8000/buildingimage/42" accept-charset="UTF-8">
<input name="_method" type="hidden" value="DELETE">
<input name="_token" type="hidden" value="EEV90wmDNLMd8hg9ilh6zdDAjVShXW9bfOCXdvml">
<button type="submit" class="btn btn-danger">
<i class="far fa-trash-alt"></i>
</button>
</form>
</td>
</tr>
My jquery code:
$('.deleteBuildingForm').on('submit', function(e) {
e.preventDefault();
axios.delete($(this).attr('action'), []).then(response => {
$(this).closest('tr').remove();
$('.successMessages').hide();
});
});