Call controller method from View

How to implement this
I want to call a method in my controller to change the items per page to be shown from my database

Attach an onChange event to the select box and make an ajax call to your controller then render the result.

2 Likes

I know its spoonfeeding but, Im a beginner on this. Can you make a snippet for me to use it for my code?

Bit of a learning curve. You need to learn some basic Javascript.

Have a play with events for example:

< select onChange="alert('gotcha')" >
...
< /select >

Then try installing jQuery via a CDN and learn how to make ajax (http) calls.

https://code.jquery.com/

Sorry, can’t walk you through it.

1 Like

I know the basic, what I need is that how to call a method from controller and render result

Hey @0wzZZzz6! :wave:

What you need to understand is the context / runtime your code is running in.

What you want to do is impossible. Adonis is purely a backend framework. That means, it’s computing an HTML and sending it back to the client. After this, the client (browser) is parsing the HTML and downloading any resources it may need (like images, scripts, css, etc.).

Since you are on the client (browser), Adonis doesn’t have any control. What you need to do is to call your application via AJAX, as @jacksoncharles said, and use the result of this.

2 Likes

thanks sir @romain.lanz, now i got some hints how to solve it :slight_smile: