Checking for AJAX Requests in PHP


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.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments