function sendIdToFrontend(){
global $post;
$postId = array('post_id' => $post->ID);
die(json_encode($postId));
}
This is my ajax function, I am at single post page. Where I've button which triggers this function. But I'm unable to get the post id. Is there anything wrong with this function ? I'm getting "null" in response.
jQuery.ajax({
url: ajax_object.ajaxurl,
type: 'POST',
dataType: 'json',
data: {'test': 'test', action: 'checkCorrectAnswersViaAjax'},
success: function(response){
console.log(response);
},
error: function(err){
console.log(err);
}
});