I'm trying to build a custom plugin for Craft CMS in which I have a button. I have managed to create the plugin and a Widget. I can add CSS and JS for the widget. Now I would like to make a call with JS when I click on the button. This call needs to be made to a function in the plugin.
I don't understand where I can write the function I want to execute when calling for a JS file. I tried finding other plugins that have a similar functionality but I can't find any which do this exact thing.
You'll need to make an 'action controller method' inside your plugin that your JS can 'hit' using AJAX.
Info on CraftCMS Action Controller Methods can be found here:
https://craftcms.com/docs/4.x/extend/controllers.html#actions