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?
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.
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With