Check if request is AJAX request


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

Quick and easy way to determine if the HTTP request is an AJAX call or a standard call. Supports the notion of Unobtrusive JavaScript.


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

URL: http://www.gmarwaha.com/blog/category/client-side/javascript/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.