$post
isn’t set in your AJAX handler, it doesn’t exist. An AJAX request is a separate request from the one that rendered the page you’re making the request from, php data doesn’t persist across these two requests. You’re passing post_id
in your AJAX request, so I assume you want something like:
function retrieve_id(){
echo $_POST['post_id'];
die;
}