I’m trying to get content from post via AJAX in WordPress
Here is the js part
$("a.ajaxed").click(function(event) {
event.preventDefault();
doAjaxRequest();
});
function doAjaxRequest(){
jQuery.ajax({
type: 'POST',
url: ajax_object.ajaxurl,
data: ({action : 'ajaxify',
post_id: $(this).attr('id')
}),
dataType: 'JSON',
success:function(data){
console.log(data.post_title);
}
});
}
This is the functions.php part
function ajaxify() {
$post_id = $_POST['post_id'];
$post_data = get_post($post_id);
echo json_encode($post_data);
}
console.log(data.post_title) always shows undefined.
post_id was undefined