I am listing the people in my database using Ajax. My files index.php and post.php are set up this way. I store Twitter users in my database and list them here. When I want to delete a user from the database, I cannot do it. I can delete by creating a button like delete.php?id=123, but it doesn't get removed instantly from the list that way. How can I ensure that the user is deleted from both the database and the list without refreshing the page when I click the delete button? Here is the code for index.php:
```html
index.php
List style:
a, a:hover {
color: black;
text-decoration: none;
}
h5 {
font-size: 1rem;
}
p {
font-size: 0.75rem;
}
```
JavaScript code:
```javascript
$(function() {
$("#cek").click(function() {
$.ajax({
url: 'post.php',
type: 'GET',
success: function(result) {
$('.row').html(result);
}
});
});
});
```
Post.php file:
```php
<?php
require("../db.php");
$cek = $db->query("SELECT * FROM users", PDO::FETCH_ASSOC);
if ($cek->rowCount()) {
foreach ($cek as $row) {
// Display user details here
}
}
?>
```
```html
index.php
List style:
a, a:hover {
color: black;
text-decoration: none;
}
h5 {
font-size: 1rem;
}
p {
font-size: 0.75rem;
}
```
JavaScript code:
```javascript
$(function() {
$("#cek").click(function() {
$.ajax({
url: 'post.php',
type: 'GET',
success: function(result) {
$('.row').html(result);
}
});
});
});
```
Post.php file:
```php
<?php
require("../db.php");
$cek = $db->query("SELECT * FROM users", PDO::FETCH_ASSOC);
if ($cek->rowCount()) {
foreach ($cek as $row) {
// Display user details here
}
}
?>
```