2016-11-22 121 views
0

何时删除通过ajax调用如何从视图中删除该内容。如何删除通知计数并删除父母删除时

这是我的阿贾克斯调用,我删除了一个工作,当它删除。

  1. 是家长要删除和
  2. 工作的通知计数已刷新(我的作业(3)它应该为2,因为只有2个工作现在已经有以dB为单位,当我退出更改和登录它未来为2)

image of deleted job not parent is not deleted.

这里是我的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> 

最后这个职位数会话从登录控制器

到来,而在我登录我stroing,乔布斯在一个会话数是这样的:

$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"; 

我想更新此会话数。我怎样才能做到这一点。?

回答

1

你的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"]); 
0

删除父类,这些都是改变我做: 查看&响应:

<div class="row" id="jobrow<?php echo $myjobs['id_job'];?>"> 
$("#jobrow"+jobId).remove(); 

用于更新计数: 视图页:

<span class="badge" id="notificationcount"> 

响应: 如果(反应[ “成功”] == TRUE){
$( “#成功消息”)显示(); $(“#success-message”)。html(response [“message”]); $(“#notificationcount”)。html(response [“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; 
}