[英]How to trigger a drupal rule from a javascript code
I don't know how to trigger drupal rule from JavaScript code. 我不知道如何从JavaScript代码触发drupal规则。
lowerLayer[image.feature_nid].on("dragend", function() {
var position = kineticImage.getPosition();
var layerPosition = this.getPosition();
var slotNid = kineticImage.slot_nid;
positionX = position.x + layerPosition.x;
positionY = position.y + layerPosition.y;
//Here I want to call drupal rule
});
I commented the line where I need to trigger drupal rule. 我评论了我需要触发drupal规则的那一行。 Can I call a drupal rule with these parameters (slotNid,positionX,positionY) like I can call some function (someFunction(slotNid,positionX,positionY).
我可以使用这些参数(slotNid,positionX,positionY)调用drupal规则吗,就像我可以调用某些函数(someFunction(slotNid,positionX,positionY)一样。
Any solutions are welcome. 欢迎任何解决方案。
As mentioned by Clive
, You can achieve this by ajax call. 如
Clive
,您可以通过ajax调用来实现。
You need to setup page callback under menu hook
in your custom module & there you can mention the function to call on page request. 您需要在自定义模块的
menu hook
下设置页面回调,并且您可以在其中提及调用页面请求的功能。
Example:
// this code will go under menu hook
$items['ajax/rule1.1'] = array(
'title' => 'Rule 1.1',
'page callback' => 'custom_rule_trigger',
'access arguments' => array('access content'),
'file' => 'custom_rules.inc',
);
// then you can write php code which you want to execute under custom_rule_trigger function in custom_rules.inc file.
function custom_rule_trigger(){
// write your rules here..
}
In javascript, you can call www.example.com/ajax/rule1.1
url to trigger your rule. 在javascript中,您可以调用
www.example.com/ajax/rule1.1
网址来触发您的规则。
Hope this will help. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.