Add Req.ajax_? function to identify ajax requests. #1252

merged 2 commits into from Apr 10, 2012


None yet

2 participants

Lift Web Framework member

Ajax requests are identified by looking for the X-Requested-With header to be set to “XMLHttpRequest”. This can be used for the purposes of, for example, deciding whether to render a layout based on the nature of the incoming request.

@Shadowfiend Shadowfiend was assigned Apr 7, 2012
@Shadowfiend Shadowfiend Add ajax_? to Req to tell whether the req was tagged as ajax.
Identification is done using the X-Requested-With header.
@Shadowfiend Shadowfiend commented on the diff Apr 7, 2012
@@ -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_? =
Shadowfiend Apr 7, 2012 Lift Web Framework member

Set this up as a def, which seems to be in keeping with a lot of other stuff in Req, but let me know if it makes more sense as a lazy val.

@Shadowfiend Shadowfiend Handle potential multiple values for X-Requested-With.
If any are XMLHttpRequest, we return true for ajax_?.
Lift Web Framework member


@dpp dpp merged commit 07c008d into master Apr 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment