Added answer here so that it can be accepted and so that other SO users don't hit this page thinking it's an unanswered question.
The problem in your example code is that no POST data is being sent with the AJAX request.
Therefore your first condition: if (!empty($_POST))
equals FALSE
and as a result none of the code within the condition is run.