Permalink
Browse files

Add ajax_? to Req to tell whether the req was tagged as ajax.

Identification is done using the X-Requested-With header.
  • Loading branch information...
1 parent a787957 commit 4cc150c45bc0fec893c9f3c2511bc2545e8704c3 @Shadowfiend Shadowfiend committed Apr 7, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 web/webkit/src/main/scala/net/liftweb/http/Req.scala
@@ -847,6 +847,18 @@ class Req(val path: ParsePath,
}
/**
+ * Returns true if the X-Requested-With header is set to XMLHttpRequest.
+ *
+ * Most ajax frameworks, including jQuery and Prototype, set this header
+ * when doing any ajax request.
+ */
+ def ajax_? =
+ request.headers.toList.exists { header =>
+ (header.name equalsIgnoreCase "x-requested-with") &&
+ (header.value equalsIgnoreCase "xmlhttprequest")
+ }
+
+ /**
* Make the servlet session go away
*/
def destroyServletSession() {

0 comments on commit 4cc150c

Please sign in to comment.