The records themselves are derived from mysql. It turns out the type code:
<tr><td>Запись 1</td><td><button id="delete" value="1">удалить</button></td></tr> <tr><td>Запись 2</td><td><button id="delete" value="2">удалить</button></td></tr> <tr><td>Запись 3</td><td><button id="delete" value="3">удалить</button></td></tr> need to implement removal. I attach the script code:
$(document).ready (function() { $("#delete").bind("click", function() { $.ajax ({ url: "/user/delete", type: "POST", data: ({name: $("#delete").val()}), dataType: "html", beforeSend: function (){ $('#delete_spinner').html('<i class="fa fa-spinner fa-spin"></i>'); }, success:function(data){ alert(data) document.getElementById('delete_spinner' ).style.display = 'none'; document.getElementById('update' ).click(); } }); }); });
The problem is that it reads by clicking on id = "delete", and since there are a lot of them, it takes the first one, respectively, but deleting the first record works. How to make to delete any entry?
$(this).val()because you need to take. But as it is written in the answers, to identify the button it is better to makeclass="delete" id="1", otherwise the identifier is not valid. - teran{ name: $(this).val() }- terandocument.getElementById('delete_spinner' ).style.display = 'none';can be written as$("#delete_spinner").toggle(false)or.hide()? - teran