当通过ajax调用删除时,如何从视图中删除该内容。?
这是我的ajax调用,我删除了一个工作。
这是我的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";
我想更新此会话计数。我怎么能这样做。?
答案 0 :(得分:1)
:
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"]);
答案 1 :(得分:0)
对于删除父类,这些是我所做的更改: 查看&amp;响应:
setTimeout(function(){
document.getElementById('vid').play();
},1000);
更新计数: 查看页面:
<div class="row" id="jobrow<?php echo $myjobs['id_job'];?>">
$("#jobrow"+jobId).remove();
响应:
if(响应[&#34;成功&#34;] == true)
{
$(&#34;#成功消息&#34)显示();
$(&#34;#成功消息&#34)。HTML(响应[&#34;消息&#34;]);
$(&#34;#notificationcount&#34)的HTML。(反应[&#34; notificationCount&#34;]);
}
控制器页面:
<span class="badge" id="notificationcount">