2016-11-22 123 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; 
}