...">

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 click this button, I need to send a hidden value that is the job id using ajax:

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

And this is 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 a hidden value:

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

My mistake is a job id value of zero.

+4
source share
4 answers

You need to change your

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

and,

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

Hope this helps!

+8
source

Change this line:

JobId = $('#JobId').val();

at

JobId = $('#JobId').text();

val() jQuery . text() html- html(), html .

+6

$_POST['JobId'] not $_GET['JobId']

+3
source

You should get it from $ _POST, not $ _GET.

+2
source

Source: https://habr.com/ru/post/1656431/


All Articles