gpt4 book ai didi

javascript - wordpress 函数没有被执行

转载 作者:行者123 更新时间:2023-11-28 17:47:28 24 4
gpt4 key购买 nike

我有这个按钮

   <button class="button1" id="myid1">Activate</button> 

当用户单击此按钮时,该 jquery 就会执行,我们也会收到警报。

jQuery(document).ready(function($) {
$(\'#myid1\').click(function(e){
e.preventDefault();
var $el = $(this).parents().eq(1);
remove_element($el);
var data1 = {
action: \'enable_function1\',
};
$.post(ajaxurl, data1, function(response) {
alert(\'Congratulations,Activated' \');
}); });
});

这是我的 WordPress 函数

function enable_function1() {
add_filter('mod_rewrite_rules', 'someotherfunction');
}

但是 mod_rewrite_rules 没有写入任何内容

最佳答案

在你的 WordPress 后端你需要这样做。 action 不是函数的名称,wordpress 使用它来识别要执行的函数

function your_function() {
add_filter('mod_rewrite_rules', 'someotherfunction');
}

add_action("wp_ajax_enable_function1", "your_function");

add_action("wp_ajax_nopriv_enable_function1", "your_function");

查看更多详细信息: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

关于javascript - wordpress 函数没有被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46364149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com