First of all, sorry for the weird title! Currently im facing the following problem:
I have a PHP script which creates a HTML button
echo '<input type="button" id="$entryID" name="change_title" value="change title" onclick="sendRequest(sendRequest($type, $entryID));" />';
This button should call a script, which creates a post request with the parameter
$type //is used to recognize which mysqli table should be adressed
$entryID //is used to recognize which entry in table sould be adressed
I know that I can not create a post request with javascript because its for front-end developement. So I have done some researches and found AJAX. So im never realy used it. But I tried to create a post request like this (in the same file):
<script>
// t = type & i = ID
function sendRequest(t, i){
var request = $.ajax({
type: "POST",
url: "admin_page.php",
data: {"type": t, "id": i},
success: function(){
console.log('request via AJAX');
}
});
return request;
}
</script>
After the script has run I use the following php script to check if it has worked:
if(isset($_POST['type'])){
if(isset($_POST['id'])){
printf('Post request sent');
}
}
I have checked the AJAX and the javascript documentations and have not found anything. It this process even possible? What am I doing wrong?
Thanks in advance.