Make JS call to custom Craft CMS plugin.

huangapple go评论49阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月7日 00:23:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定