Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the isAjax() method in Play Framework 2.0?

In Play Framework 1.x, we could quickly know if the request was AJAX or not by asking request.isAjax() method, but I can't find it on Play 2.

What is the alternative or where is this method?

like image 453
Cyril N. Avatar asked Apr 26 '12 09:04

Cyril N.


2 Answers

If you use JQuery for Ajax, it sets the following Request Header:

 X-Requested-With: XMLHttpRequest

that you can later access to test if a call is done via Ajax or not.

like image 138
Pere Villega Avatar answered Sep 22 '22 01:09

Pere Villega


You can define it as a method and use it in your controller:

def isAjax[A](implicit request : Request[A]) = {
  request.headers.get("X-Requested-With") == Some("XMLHttpRequest")
}
like image 25
phidias Avatar answered Sep 20 '22 01:09

phidias