I have a datatable with two column, "Name" and "Age" and after I fill the datatable with Ajax I create a button (one per row). This works fine. But after the user click on a button the two field (name and age) of that row should be sent to a php and then make an alert like this "Hello, my name is [name] and i'm [age] years old". (i need the php here). I wrote a code that can call the php but i don't know how to send the parameters of each row to the php. How can i do this?
My js:
<script type="text/javascript">
$(document).ready(function() {
var oTable = $('#jsontable').dataTable(
$('td:eq(2)', nRow).html("<input type='button' id='button' onclick='test();' value='Click to Release'></input>");
); ///This is created after ajax
$('#load').on('click',function(){
var user = $(this).attr('id');
if(user != '')
{
$.ajax({
url: 'response.php?method=fetchdata',
type: 'POST',
data: {id1: $('#id1').val()},
dataType: 'json',
success: function(s){
console.log(s);
oTable.fnClearTable();
for(var i = 0; i < s.length; i++) {
oTable.fnAddData([
s[i][0],
s[i][1]
]);
} // End For
},
error: function(e){
console.log(e.responseText);
}
});
}
});
});
function test() {
$.ajax( { type : 'POST',
data : { },
url : 'process_form.php', // <=== CALL THE PHP FUNCTION HERE.
success: function ( data ) {
alert( data ); // <=== VALUE RETURNED FROM FUNCTION.
},
error: function ( xhr ) {
alert( "error" );
}
});
}
</script>
process_form.php
<?php
function bb()
{
echo "hellooooo"; //How to pass the name and the age field to php here from each row of the datatable?
}
bb();
?>