WordPress插件管理员ajax不再工作了



所以我做了一个WordPress插件,在管理页面中使用ajax调用。它在我的所有测试站点和服务器上都可以正常工作,但现在我在安装了多个其他插件的更大站点上对其进行了测试。我不知道为什么,但是如果我按下调用ajax请求的按钮,则什么都不会发生。

这是我的 ajax 调用的代码:

jQuery.ajax({
    url: "../wp-content/plugins/autocommerce/admin/activatePlugin.php?activate=true",
    method: "POST",
    data: { txtAC : txtAC, txtKey: txtKey }
}).done(function(msg) {
    if(msg == "success") {
        jQuery("#admin_activate").append('<input type="hidden" name="txtActivated" value="true" />');
        jQuery("#admin_activate").submit();
    } else if(msg == "failed") {
        jQuery("#activateError").html("Gegevens onjuist. Controleer uw gegevens en probeer het opnieuw.");
    } else if(msg == "notSet") {
        jQuery("#activateError").html("Een of meerdere velden zijn onjuist ingevuld.");
    } else {
        alert(msg);
        jQuery("#activateError").html("Er is een fout opgetreden. Probeer het later opnieuw.");
    }
});

没有错误,在其他网站上它只是工作,所以我不知道从哪里开始寻找解决这个问题。

我希望有人能帮助我。

我建议使用wordpress标准ajax,而不是对自己的php文件进行ajax调用:

add_action('wp_ajax_yourfunction', 'yourfunction');
add_action('wp_ajax_nopriv_yourfunction', 'yourfunction');
function nsds_change_password() { 
//your functional part goes here
}

然后在 ajax 调用中使用管理员 ajax url,它可以像这样预先输出:

<script type='text/javascript'> var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; </script>

并使用 ajaxurl 作为变量并设置附加操作参数,这将是您的函数名称。

最新更新