2016-11-22 14 views
0

при удалении корыта вызова ajax, как удалить этот контент из представления.?Как обновить подсчет уведомлений и удалить родительский объект при его удалении

этот мой вызов ajax, и я удаляю работу оттуда, когда он удаляет.

  1. , что родитель должен удалить и
  2. счетчик уведомлений задания должен обновить (МОЯ РАБОТА (3) она должна измениться 2, потому что есть только 2 рабочих мест есть в настоящее время в дб, когда я выйти из системы и войти в его подходит как 2.)

image of deleted job not parent is not deleted.

Вот мой Аякса код контроллера:

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; 
} 

Моего Аякс вызова и отправка запрос:

<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> 

И, наконец, рассчитывать эту работу сессия исходит от контроллера

логина при входе в I Am 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

на вашем АЯКС страницы контроллера:

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) {
$ ("Успех-сообщение #") шоу(); $ ("# успешное сообщение"). 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; 
}