0
Guys I’m with the following situation, I make an append and inside it I need to send a delete method, to treat it in the web service I’m having doubts, I’ve tried to create a form inside, but it doesn’t work, detail if I put the link "http://localhost/projectohtml/admin/users/'+v.iduser+'/delete" inside href it works but in the webservice dealing with delete method or whatever it requires it to be this method, and if I change in the webservice to get it works, but it’s not safe, jquery code, :
<script>
$(document).ready(function(){
$.getJSON('http://localhost/projetohtml/admin/users-list-all',function(data){
$.each(data, function(k, v){
$('#table-users').append("<tr>"+'<td>'+v.iduser+'</td>'+
'<td>'+v.desperson+'</td>'+
'<td>'+v.desemail+'</td>'+
'<td>'+v.deslogin+'</td>'+
'<td>'+v.inadmin+'</td>'+
'<td><a href="/projetohtml/admin/users/'+v.iduser+'"class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> Editar</a></td>"'+
'<form action="http://localhost/projetohtml/admin/users/'+v.iduser+'/delete" id="form-delete" method="delete">'+
'<td><a href="#" id="iduser-delete" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> Excluir</a></td>'+'</form>'+"</tr>");
});
});
});
</script>
Instead of using a form, make an Ajax that will be fired in the event of clicking on a certain delete button, passing as parameter the ID of the item you want to remove.
– Kayo Bruno
i tried to do with ajax, but it seems that after the append in the id of <a href> ajax does not recognize the element, I do not know why, but I did the same code with ajax and did not give.
– Felipe Sangiorge
This happens because the element was not loaded in the DOM, but this is simple to solve. I will put as an answer to help you.
– Kayo Bruno
Beauty’s waiting for me, thanks
– Felipe Sangiorge