如何刷新通知计数并在删除父项时删除它

时间:2016-11-22 06:33:07

标签: php jquery ajax parent-child removechild

当通过ajax调用删除时,如何从视图中删除该内容。?

这是我的ajax调用,我删除了一个工作。

  1. 父母必须删除
  2. 作业通知计数必须刷新(MY JOBS(3)它应该更改为2,因为当我退出并登录它时,db中现在只有2个作业。)
  3. 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>
    

    最后,这个作业计数会话来自登录控制器

    登录时,我正在努力计算这样的会话:

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

    我想更新此会话计数。我怎么能这样做。?

2 个答案:

答案 0 :(得分: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"]);

答案 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">