Detect an AJAX request in your PHP script.
Source Code
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "This is an AJAX request.";
} else {
echo "This is not an AJAX request.";
}