douyinliu8813 2016-10-03 12:35 采纳率: 100%
浏览 55
已采纳

如何发送JobId并在视图上追加值。 阿贾克斯

enter image description here

This is the lotal listing fetching from the data base r_job table.. When i click view Details button it has to take the job value to controller page through ajax and there i will fetch the job information and in responsense i have to send job related table feillds and have to display on this page.

This is my Dynamic Listing:

$Jobquery = $conn->query("SELECT * FROM r_job ");
while($JobResults = $Jobquery->fetch_assoc()){

<tr>
    <td id="hiringevent"><?php echo $JobResults['hiringevent']; ?></td>
    <td id="JobId"><?php echo $JobResults['id_job']; ?></td>
    <td><button id="ViewDetails" class="btn btn-primary text-center">View Details</button></td>
</tr>

And this is my ajax and jquery Call:

$("#ViewDetails").click(function() {
    $.ajax({
            url: "job-controller.php",
            method: "POST",
            data: {'action':'viewjob','JobId' : + $('#JobId').html()},
            dataType: "json",
            success: function (response) {
                $("#showMessage").html(response['message']);
            },
            error: function (request, status, error) {
                $("#showMessage").html("OOPS! Something Went Wrong Please Try After Sometime!");
            }
        }); 
        return false;
    });

Finally my Controller Page:

if($_POST['action']=='viewjob'){ 
        $jobSearch= $conn->query("SELECT * From r_job WHERE id_job='".$_POST['JobId']."'") or die(mysql_error());
        $ViewJob=$jobSearch->fetch_assoc();
        $hiringevent        =   $ViewJob['hiringevent'];
        $jobname            =   $ViewJob['jobname'];
        $jobdescription     =   $ViewJob['jobdescription'];
        $cutoff             =   $ViewJob['cutoff'];
        $joblocation        =   $ViewJob['joblocation'];
        $interviewlocation  =   $ViewJob['interviewlocation'];
        $jobexperience      =   $ViewJob['jobexperience'];
            $response['message'] = "Show Job Information";
            $response['success'] = true;
            }else{
            $response['message'] = "OOPS! Something Went Wrong Please Try After Sometime!";
            $response['success'] = false;
        }
        echo json_encode($response);
        exit;
    }

My current issue is when i click view details only first view details button working remaining no response

  • 写回答

2条回答 默认 最新

  • duanlian1978 2016-10-04 04:58
    关注

    Note there should a single id per page. all you need to do is, create a js function and call it when button is clicked and send the JobId as a parameter. that works fine when you are in Loop.

    HTML

    $Jobquery = $conn->query("SELECT * FROM r_job ");
    while($JobResults = $Jobquery->fetch_assoc()){
    
    <tr>
        <td id="hiringevent"><?php echo $JobResults['hiringevent']; ?></td>
        <td id="JobId"><?php echo $JobResults['id_job']; ?></td>
        <td><button class="btn btn-primary text-center" onClick="getDetails(<?php echo $JobResults['id_job']; ?>)">View Details</button></td>
    </tr>
    }
    

    JS

    function getDetails(jobID){
    // ajax Call Here
    console.log(jobID)// you can see JobID Here.
    // now set the values to by using id
    $("#ViewJobId").val(response['jobData']['jobId']);
    /* val is used to set aswell as get the values */
    
    
    
      /*in case of td you have to use text insted of val*/
       $("#ViewJobId").text(response['jobData']['jobId']);
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。