1
Buenas! I looked for some topics about the same doubt as mine - and I found, but I could not understand how to do... I have the following code snippet:
$c = array();
$c = buscaUsuario($conexao);
while($b = mysqli_fetch_assoc($c))
{?>
<tr>
<td><?php echo $b["user_name"]; ?></td>
<td><?php echo $b["user_fullname"]?></td>
<td><?php echo $b["user_email"]?></td>
<td>
<div class="btn-group">
<a class="btn btn-primary" href="#"><i class="icon_plus_alt2"></i></a>
<a class="btn btn-danger" onclick="deletarUsuario();"><i class="icon_close_alt2"></i></a>
</div>
</td>
And when you click the delete button it will call a js function called deletarUsuario(), where the id of that item will be passed. In this function, this is where I have to use Ajax, but I don’t know how to do it! I don’t know how to join the query of delete + javascript + ajax.
The reason I want to do this, is that by clicking the remove such item button, it removes without needing me to refresh the page.
This. With the $b variable I can recover the id, like this:
$b['id'];
As I have no idea how to use Ajax, I was doing it this way:
<a class="btn btn-danger" href="procura-cadastro.php?id=<?php echo $b['id'] ?>">
<?php
if(array_key_exists("id", $_GET) && $_GET['id'] == $b['id'])
{
$a = $_GET['id'];
$b = deletaUsuario($conexao, $a);
}
}
?>
Which url to delete the user?
– Laerte
I forgot to add, sorry. I have a page called deleta-item.php and in it, is where I put the query that deletes some item.
– Cesar Augusto
It takes the id by parameter to be deleted
deleta-item.php?id=1
?– Laerte
Laerte, I’m going to edit my question with the piece of code I put here to be better to view...
– Cesar Augusto