3.6. Please advice in a conceptional question about using helper and ajax

Hi,

I have a little search form on my homepage with a html select using database data. It shows categories.
Therefore I created a Helper which does TableRegistry to the table holding the data and query the data. This way I can reuse the call in any view at any time.

But now, I need to update the html select based on a onChange Event via Ajax.
And I wonder what will be the solution for this in order to avoid an replication of code.

To call ajax I need a function in a controller.
But I can’t call a helper from a controller right?

I am stuck here … please advice the proper way of doing this…
I can’t imagine that I am the first person with such an isseu :slight_smile:

You don’t mention if using ajax normal, or something like jquery. But I’d highly advise learning (if jquery) some basics of jquery ajax first. I am talking about in regular php first no framework. Then all will fall into place.

There are many free youtube videos and tutorials on the web on how to do all kinds of things with ajax and javascript.

Inside of a framework it is similar, you load the jquery usually in the layout, and the script is normally in the view at bottom.

But if you do a few practice tutorials it will all make more sense.

1 Like