javascript - Notification functionality using ajax php
one text
Here I am stuck in a problem that is not bigger but I don't know why it's not working. There is a table name task and a column status through a notification is shown on a webpage. I am using ajax to update column values but the problem is ajax request is executed but the PHP file code is not running, I don't know why is this happening.
PHP code to show data
<button class="notification-btn">
<ul class="notification-drop">
<li class="item">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-bell">
<path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9" />
<path d="M13.73 21a2 2 0 0 1-3.46 0" />
</svg>
<span class="btn__badge pulse-button" id="noti_hide">
<?php
$qs11 = "SELECT task FROM `task` where employee_id='{$session_id}' AND status='unseen'";
// echo "$q11";
// die();
$trs1 = mysqli_query($con, $qs11) or die("query failed for row");
$trows1 = mysqli_num_rows($trs1);
echo $trows1;
?>
</span>
<ul>
<?php
$qz1 = "SELECT task FROM `task` where employee_id='{$session_id}' AND status='unseen'";
$result = mysqli_query($con, $qz1) or die("query 1 failed ");
if (mysqli_num_rows($result) > 0 ) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<li>'.$row['task'].'</li>';
}
}
?>
</ul>
</li>
</ul>
</button>
ajax code
document).ready(function() {
$(".notification-btn .item").on('click',function() {
$(this).find('ul').toggle();
$.ajax({
url : "update.php",
type : "POST",
data : 'get',
success : function(data){
$('#noti_hide').fadeOut('slow');
console.log("success");
},
error: function(){
console.log("error");
}
});
});
});
update.php
<?php
include('db.php');
session_start();
if ($_SESSION['employee_name'] == "") {
header("location:index.php");
}
$session_id = $_SESSION['employee_id'];
$upd_qry = "UPDATE `task` SET status='seen' WHERE employee_id=$session_id AND status='unseen'";
mysqli_query($con,$upd_qry);
?>
Source