We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

TC on 09/12/06


Tagged

ajax php


Versions (?)


Who likes this?

12 people have marked this snippet as a favorite

Hollow
frankyfish
simpeligent
vali29
willcodeforfood
jeff
Steffen82
romanos
grn
ki4ngel
dave333
elgermano


Check for AJAX Request


Published in: PHP 


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: http://jquery.com/discuss/2006-June/006656/

  1. function isAjax() {
  2. return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  3. ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
  4. }

Report this snippet 

You need to login to post a comment.