Check for AJAX Request

/ Published in: PHP
Save to your folder(s)

A simple function to check if the request comes from an AJAX XMLHttpRequest.
Use it if your page should behave differently when called from AJAX.
Comes from jquery mailing list:

Copy this code and paste it in your HTML
  1. function isAjax() {
  2. return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  3. ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
  4. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.