← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1767: [core] Add AnewtRequest::is_ajax() method

 

------------------------------------------------------------
revno: 1767
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Wed 2010-02-24 23:14:12 +0100
message:
  [core] Add AnewtRequest::is_ajax() method
  
  ...with a heuristic to detect Ajax/XMLHttpRequest requests.
modified:
  core/request.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'core/request.lib.php'
--- core/request.lib.php	2009-08-02 20:19:16 +0000
+++ core/request.lib.php	2010-02-24 22:14:12 +0000
@@ -305,6 +305,18 @@
 		return AnewtRequest::method() === 'POST';
 	}
 
+	/**
+	 * Check if the request is an AJAX/XMLHttpRequest.
+	 *
+	 * This is based on a heuristic: if the
+	 * <code>X-Requested-With</code> HTTP header equals
+	 * <code>XMLHttpRequest</code> the request is considered an AJAX request;
+	 * otherwise it is not.
+	 */
+	public static function is_ajax()
+	{
+		return array_get_default($_SERVER, 'HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest';
+	}
 
 	/* Integers */