I am new to AJAX so I know there could be a silly mistake in my code but anyways I will go ahead.
I have a function created that is called when a button is clicked. The function calls .ajax()
method of jquery. I send the data to a file named 'delete_post.php`.
HTML:
<button class="btn btn-primary" onclick="deletePost(<?php echo $_GET["id"]; ?>);">Yes</button>
The above code works.
JS:
function deletePost(postid) {
$.ajax({
type: 'post',
url: "delete_post.php?id="+postid,
success: function(data) {
if(data.error == true) console.log('error');
else console.log('problem?');
}
});
}
The above code is calling the .ajax()
function but is not logging 'problem?' into the console.
Here's the PHP file:
<?php
require_once '...';
if(isset($_GET["id"])) {
$id = $_GET["id"];
echo "YEAH!";
} else {
header("location: index.php");
}
?>
What's the issue and how can I fix it?