Abdul Waheed Abdul Waheed - 11 days ago 6
Javascript Question

How can i send dynamic values using ajax

Here my dynamic script:

<a href="inv-controller.php?res=yes&id_job=<?=$myjobs['id_job'];?>" class="btn btn-primary">Accept And Send Invite To All Students</a>
<a href="inv-controller.php?res=no&id_job=<?=$myjobs['id_job'];?>" class="btn btn-default">Reject And Delete</a>


From the above two links there are two dynamic parameters which i want to send using ajax call how can i do that..?

There are two buttons there Accept and reject.
i can do this with core php and i want to do this without refreshing the page.

Here what i have tried.

<script type="text/javascript">
function jobResponse(jobId){
var jobid = $(jobId).attr('id'); // im confusing in this line
$.ajax({
method: "POST",
url: 'inv-controller.php',
data: {action: "jobreplay", value: jobid},
dataType: "json",
success: function(response) {
//blah blah blah
}
});
}
</script>


how can i rewrite the two
<a>
tags according to ajax.

Answer
<a href="javascript:;" class="btn btn-primary" onclick="jobResponse("yes",<?php echo $myjobs['id_job'];?>)">Accept And Send Invite To All Students</a>
<a href="javascript:;" class="btn btn-default" onclick="jobResponse("no",<?php echo $myjobs['id_job'];?>)">Reject And Delete</a>

and get in function like this

function jobResponse(type,jobId){

var frm_data = { type : type,
                 jobId : jobId
                }
    $.ajax({
        method: "POST",
        url: 'inv-controller.php',
        data: frm_data,
        dataType: "json",
        success: function(response) {
            //blah blah blah
        }   
    });
}

you can get in your ajax php file. frm data as post .

Comments