英文:
Make JS call to custom Craft CMS plugin
问题
I'm trying to build a custom plugin for Craft CMS in which I have a button.
我正在尝试构建一个用于Craft CMS的自定义插件,其中我有一个按钮。
I have managed to create the plugin and a Widget. I can add CSS and JS for the widget.
我已成功创建了插件和一个小部件。我可以为小部件添加CSS和JS。
Now I would like to make a call with JS when I click on the button.
现在,当我单击按钮时,我想使用JS进行调用。
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.
我不明白在哪里编写我想要在调用JS文件时执行的函数。
I tried finding other plugins that have a similar functionality but I can't find any which do this exact thing.
我尝试查找其他具有类似功能的插件,但我找不到做这一点的插件。
英文:
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.
答案1
得分: 0
需要在你的插件中创建一个“操作控制器方法”,以便你的JS可以使用AJAX进行访问。
有关CraftCMS操作控制器方法的信息可以在这里找到:
https://craftcms.com/docs/4.x/extend/controllers.html#actions
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论