# Cake4: Beginner question. How use the ajax function

**URL:** <https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217>\
**Category:** Need Help\
**Tags:** help\
**Created:** [April 7, 2021, 9:40pm UTC](https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217 "2021-04-07T21:40:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![by\_spix](https://avatars.discourse-cdn.com/v4/letter/b/edb3f5/32.png) [@by\_spix](https://discourse.cakephp.org/u/by_spix)\
**Post date:** [April 7, 2021, 9:40pm UTC](https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217/1 "2021-04-07T21:40:15Z")

</div>

Sorry, I’m migrated a complete application from cake 1.2 to 4.2.  
In the old version I had $ajax-\>observeField to permit me modify a select run time.  
With the 4.2 I don’t find similar solution.  
Thank’s for help me.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 7, 2021, 10:47pm UTC](https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217/2 "2021-04-07T22:47:55Z")

</div>

The Ajax helper went away a long time ago, due to the proliferation of JS solutions and impossibility of supporting all of them. There should be a load of non-Cake-specific tutorials out there about how to accomplish the same from the client side, and on the Cake side you just need to build an action that the client side can call.

---

<div class="post-metadata">

**Author:** ![Jawfin](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@Jawfin](https://discourse.cakephp.org/u/Jawfin)\
**Post date:** [April 8, 2021, 6:20am UTC](https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217/3 "2021-04-08T06:20:24Z")

</div>

As Cake is a server-side PHP framework I understand why they stopped attempting to support client-side javascript stuff.

I put together my approach to AJAX which uses both CSRF & form tampering protection here:-

> [@Working CSRF AJAX in CakePHP 4 - looking for criticism!](https://discourse.cakephp.org/t/working-csrf-ajax-in-cakephp-4-looking-for-criticism/7714/5):
>
> This is a complete build of a running AJAX using CakePHP4 with CSRF and Form Tampering protection. It reverses a user entered string. Create the ajax project: - composer self-update && composer create-project --prefer-dist cakephp/app:4.\* ajax Edit config/app\_local.php ... 'username' =\> 'root', 'password' =\> 'secret', 'database' =\> 'cake\_ajax', ... Or whatever your database is. For this demonstration I am using this table: - DROP TABLE IF EXISTS `myajax`; CREATE TABLE `myajax` ( …

I can only assume its a correct working approach as no-one yet has told me different!

---

<div class="post-metadata">

**Author:** ![by\_spix](https://avatars.discourse-cdn.com/v4/letter/b/edb3f5/32.png) [@by\_spix](https://discourse.cakephp.org/u/by_spix)\
**Post date:** [April 8, 2021, 6:55am UTC](https://discourse.cakephp.org/t/cake4-beginner-question-how-use-the-ajax-function/9217/4 "2021-04-08T06:55:46Z")

</div>

Thanks for the answers both.
