Abdul Waheed Abdul Waheed - 1 year ago 58
PHP Question

How can i send JobId and append values on view. Ajax

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()){

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

And this is my ajax and jquery Call:

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

Finally my Controller Page:

$jobSearch= $conn->query("SELECT * From r_job WHERE id_job='".$_POST['JobId']."'") or die(mysql_error());
$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;
$response['message'] = "OOPS! Something Went Wrong Please Try After Sometime!";
$response['success'] = false;
echo json_encode($response);

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

Answer Source

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.


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

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


function getDetails(jobID){
// ajax Call Here
console.log(jobID)// you can see JobID Here.
// now set the values to by using id
/* val is used to set aswell as get the values */

  /*in case of td you have to use text insted of val*/