I don't know much about the ajax and its functionality. I wanted to call a php page from another php page through ajax call but its not working. I just wanted the alert to be displayed which is in the "delete.php" when I press a delete button from the "index.php".
dbconnect.php
<?php
$conn = new mysqli($host, $user, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
config.php
<?php
$host="192.168.20.171";
$user="production";
$password="******";
$database="*****";
?>
index.php
<html>
<?php
include 'config.php';
include 'dbconnect.php';
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<table border="1">
<tr>
<th>categoryId</th>
<th>category</th>
<th>Operations</th>
</tr>
<?php
$sql_query = "select category_id,category from cscart_category_descriptions;";
$result = $conn->query($sql_query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<tr><td>'.$row["category_id"].'</td><td>'.$row["category"].'</td><td><button class="deletedata" data-id="'.$row['category_id'].'">Del</button></td></tr>';
}
}
else {
echo "0 results";
}
?>
<script>
$(document).on('click','.deletedata',function(){
id = $(this).attr('data-id'); // Get the clicked id for deletion
$.ajax({
type:'GET',
url:'delete.php',
data:{delete_id:id},
success:function(response){
if (response == 'ok') {
alert("succes");
} else {
alert("fail");
}
}
})});
</script>
</table>
</html>
delete.php
<?php
include 'config.php';
include 'dbconnect.php';
if($_GET('delete_id'))
{
echo"<script>alert('jjjj');</script>";
}
?>