I want to call a parameterised function in PHP. I am using AJAX for that.
This is my dynamic button. I need to pass $sub_id
to the delet(sub_id)
function and perform there some SQL.
echo "<td><input type='submit' name='disable' value='Disable' onClick='delet($sub_id);'/></td>";
This is my script so far:
<script>
function delet(sub_id) {
alert("sub ID = " + sub_id);
jQuery.ajax({
type: 'GET',
url: '/my_page',
data: {
ID: sub_id
}
}).done(function(msg) {
alert("Data Saved: " + msg);
});
}
</script>
and this is PHP function:
function delet($ID){
echo $ID;
//do sql stuff...
}
All the code is in one file and I am doing this in wordpress default template swentysixteen. so there is no .php extension to my page.
when I click on the dynamic button, I am getting 404 error in url parameter of ajax. When I see console, the url link seems to be correct.
Please help me in this issue. Thanks.