Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send and receive hidden value using Ajax

This is my job id which is in php.

<td id="JobId"><?php echo $JobResults['id_job']; ?></td>

This is my reinvite button when i clicks this button i have to send hidden value that is job id using ajax:

<button id="ReInvite">Reinvite</button>

And this my ajax call:

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

this is my controller page to call the hidden value:

if($_POST['action']=='reinvite'){ 
    $Jobid = trim($_GET['JobId']);
    echo $JobId;
    exit;
});

My Error is job id value is coming as zero.

like image 810
Mr world wide Avatar asked Dec 01 '22 16:12

Mr world wide


1 Answers

You need to change your,

data: {'action':'reinvite','JobId' : + JobId},

as,

{'action':'reinvite','JobId' : + $('#JobId').text()},

Hope this helps!

like image 58
David R Avatar answered Dec 04 '22 10:12

David R