如何在删除时刷新通知计数并删除 parent
How can i refresh notification count and remove parent when it is deleted
当通过 ajax 调用删除时,如何从视图中删除该内容?
这是我的 ajax 电话,当它删除时我正在从那里删除作业。
- parent 必须删除并且
- 作业通知计数必须刷新(我的作业 (3) 它应该更改为 2,因为当我注销并登录时,数据库中现在只有 2 个作业,它是 2。)
这是我的 ajax 控制器代码:
elseif(isset($_POST['res'])&& ($_POST['res'] =='no'))
{
$jobId=$_POST['jobId'];
$updateStatus=$conn->query("UPDATE r_job_invitations SET inv_res='2' WHERE id_job='".$jobId."' ");
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['success'] = true;
} else {
$response['message'] = "<strong>Warning!</strong> There is an error in Job Rejection please try again";
$response['success'] = false;
}
echo json_encode($response);
exit;
}
我的ajax呼叫和发送请求:
<a href="javascript:;" class="btn btn-default" onclick="jobResponse('no',<?php echo $myjobs['id_job'];?>)">Reject And Delete</a>
<script type="text/javascript">
function jobResponse(res,jobId){
var frm_data = { res : res,
jobId : jobId
}
$.ajax({
method: "POST",
url: 'inv-controller.php',
data: frm_data,
dataType: "json",
success: function (response) {
if (response["success"] == true)
{
$("#success-message").show();
$("#success-message").html(response["message"]);
} else {
$("#warning-message").show();
$("#warning-message").html(response["message"]);
}
},
error: function (request, status, error) {
$("#warning-message").show();
$("#warning-message").html("OOPS! Something Went Wrong Please Try After Sometime!");
}
});
}
</script>
最后这个作业计数会话来自登录控制器
登录时,我正在检查作业在会话中的计数,如下所示:
$Query = $conn->query("SELECT count(*) as notificationCount FROM r_job_invitations where email='".$_SESSION['user_email']."' and inv_res=0") or die(mysqli_error());
$notification = mysqli_fetch_assoc($Query);
$_SESSION['notificationCount'] = $notification['notificationCount'];
echo BASE_URL."my-profile.php";
我想更新此会话计数。我该怎么做呢?
在您的 ajax 控制器页面上:
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['success'] = true;
$response['newCount'] = $_SESSION['notificationCount']+1;
$_SESSION['notificationCount']++;
......
然后在你的 jquery
if (response["success"] == true)
{
$("#success-message").show();
$("#success-message").html(response["message"]);
$('selector_that_has_your_old_count').html(response["newCount"]);
为了删除父 class 这些是我所做的更改:
查看和回复:
<div class="row" id="jobrow<?php echo $myjobs['id_job'];?>">
$("#jobrow"+jobId).remove();
更新计数:
查看页面:
<span class="badge" id="notificationcount">
回复:
如果(响应["success"] == 真)
{
$("#success-message").show();
$("#success-message").html(响应["message"]);
$("#notificationcount").html(响应["notificationCount"]);
}
控制器页面:
$Query = $conn->query("SELECT count(*) as notificationCount FROM r_job_invitations where email='".$_SESSION['user_email']."' and inv_res=0") or die(mysqli_error());
$notification = mysqli_fetch_assoc($Query);
$_SESSION['notificationCount'] = $notification['notificationCount'];
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['notificationCount'] = $_SESSION['notificationCount'];
$response['success'] = true;
} else {
$response['message'] = "<strong>Warning!</strong> There is an error in Job Rejection please try again";
$response['success'] = false;
}
echo json_encode($response);
exit;
}
当通过 ajax 调用删除时,如何从视图中删除该内容?
这是我的 ajax 电话,当它删除时我正在从那里删除作业。
- parent 必须删除并且
- 作业通知计数必须刷新(我的作业 (3) 它应该更改为 2,因为当我注销并登录时,数据库中现在只有 2 个作业,它是 2。)
这是我的 ajax 控制器代码:
elseif(isset($_POST['res'])&& ($_POST['res'] =='no'))
{
$jobId=$_POST['jobId'];
$updateStatus=$conn->query("UPDATE r_job_invitations SET inv_res='2' WHERE id_job='".$jobId."' ");
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['success'] = true;
} else {
$response['message'] = "<strong>Warning!</strong> There is an error in Job Rejection please try again";
$response['success'] = false;
}
echo json_encode($response);
exit;
}
我的ajax呼叫和发送请求:
<a href="javascript:;" class="btn btn-default" onclick="jobResponse('no',<?php echo $myjobs['id_job'];?>)">Reject And Delete</a>
<script type="text/javascript">
function jobResponse(res,jobId){
var frm_data = { res : res,
jobId : jobId
}
$.ajax({
method: "POST",
url: 'inv-controller.php',
data: frm_data,
dataType: "json",
success: function (response) {
if (response["success"] == true)
{
$("#success-message").show();
$("#success-message").html(response["message"]);
} else {
$("#warning-message").show();
$("#warning-message").html(response["message"]);
}
},
error: function (request, status, error) {
$("#warning-message").show();
$("#warning-message").html("OOPS! Something Went Wrong Please Try After Sometime!");
}
});
}
</script>
最后这个作业计数会话来自登录控制器
登录时,我正在检查作业在会话中的计数,如下所示:
$Query = $conn->query("SELECT count(*) as notificationCount FROM r_job_invitations where email='".$_SESSION['user_email']."' and inv_res=0") or die(mysqli_error());
$notification = mysqli_fetch_assoc($Query);
$_SESSION['notificationCount'] = $notification['notificationCount'];
echo BASE_URL."my-profile.php";
我想更新此会话计数。我该怎么做呢?
在您的 ajax 控制器页面上:
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['success'] = true;
$response['newCount'] = $_SESSION['notificationCount']+1;
$_SESSION['notificationCount']++;
......
然后在你的 jquery
if (response["success"] == true)
{
$("#success-message").show();
$("#success-message").html(response["message"]);
$('selector_that_has_your_old_count').html(response["newCount"]);
为了删除父 class 这些是我所做的更改: 查看和回复:
<div class="row" id="jobrow<?php echo $myjobs['id_job'];?>">
$("#jobrow"+jobId).remove();
更新计数: 查看页面:
<span class="badge" id="notificationcount">
回复:
如果(响应["success"] == 真)
{
$("#success-message").show();
$("#success-message").html(响应["message"]);
$("#notificationcount").html(响应["notificationCount"]);
}
控制器页面:
$Query = $conn->query("SELECT count(*) as notificationCount FROM r_job_invitations where email='".$_SESSION['user_email']."' and inv_res=0") or die(mysqli_error());
$notification = mysqli_fetch_assoc($Query);
$_SESSION['notificationCount'] = $notification['notificationCount'];
if ($updateStatus) {
$response['message'] = "<strong>Success!</strong> Job Rejected.";
$response['notificationCount'] = $_SESSION['notificationCount'];
$response['success'] = true;
} else {
$response['message'] = "<strong>Warning!</strong> There is an error in Job Rejection please try again";
$response['success'] = false;
}
echo json_encode($response);
exit;
}