# $request-\>ajax() no longer supported

**URL:** <https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202>\
**Category:** Questions\
**Tags:** v3\
**Created:** [August 9, 2019, 11:21am UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202 "2019-08-09T11:21:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hvsrmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hvsrmusic/32/2722_2.png) [@hvsrmusic](https://forum.getkirby.com/u/hvsrmusic)\
**Post date:** [August 9, 2019, 11:21am UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/1 "2019-08-09T11:21:36Z")

</div>

Hi, i read that the method $request-\>ajax() is deprecated from Kirby 3.1

So, which is the best method to know if a request come from ajax or not, then? Is the following code reliable?

```
if ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
{
      //now I know it's ajax
}

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 9, 2019, 11:29am UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/2 "2019-08-09T11:29:47Z")

</div>

I’d either work with a [content representation](https://getkirby.com/docs/guide/templates/content-representations) or a route that handles AJAX requests.

See also this issue as to why the method was deprecated: [https://github.com/getkirby/kirby/issues/1431](https://github.com/getkirby/kirby/issues/1431)

---

<div class="post-metadata">

**Author:** ![hvsrmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hvsrmusic/32/2722_2.png) [@hvsrmusic](https://forum.getkirby.com/u/hvsrmusic)\
**Post date:** [August 10, 2019, 1:10pm UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/3 "2019-08-10T13:10:14Z")

</div>

Thank you @texnixe

---

<div class="post-metadata">

**Author:** ![\_gareth\_j](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/_gareth_j/32/4694_2.png) [@\_gareth\_j](https://forum.getkirby.com/u/_gareth_j)\
**Post date:** [August 10, 2019, 7:35pm UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/4 "2019-08-10T19:35:32Z")

</div>

It would be really helpful to a cookbook example of an Ajax request e.g updating a page field.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2019, 7:47pm UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/5 "2019-08-10T19:47:51Z")

</div>

Ajax stuff is on my list. But in reality it is no more than calling a route from JS that then handles the updating and returns a response.

---

<div class="post-metadata">

**Author:** ![warg](https://avatars.discourse-cdn.com/v4/letter/w/90ced4/32.png) [@warg](https://forum.getkirby.com/u/warg)\
**Post date:** [August 10, 2019, 7:52pm UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/6 "2019-08-10T19:52:00Z")

</div>

A general question: Am I right that the main difference between the API and the custom routes are that I have to code the custom routes myself and they are not protected by authorization while the API is always auth protected, even for simple, safe read operations on the cms content? I’m curious about this for some time because I wasn’t sure what’s the best way to offer a public (read- or insert-only limited) API for my Kirby 3 content.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2019, 7:54pm UTC](https://forum.getkirby.com/t/request-ajax-no-longer-supported/15202/7 "2019-08-10T19:54:53Z")

</div>

The API always needs authentication, yes. With your custom routes, it’s up to you to authenticate, unless you use methods that need authentication (like updating etc, via a logged in user, or impersonation)
