在 wordpress 插件中收到 400 个错误的请求? [英] Getting 400 bad request in wordpress plugin?
本文介绍了在 wordpress 插件中收到 400 个错误的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击插件中的按钮时收到 400 个错误请求.有没有缺失的功能?请就此提出建议.
I am getting 400 bad request when clicking the button from plugin. Is there any missing function? please advise on this.
jQuery.ajax({
type : "POST",
dataType : "json",
url : "<?php echo admin_url('admin-ajax.php'); ?>",
data : {action: "get_process_payment"},
success: function(response) {
alert("Your vote could not be added");
alert(response);
}
});
function get_process_payment(){
echo "test";
wp_die();
}
推荐答案
在 WordPress 中,wp_ajax_nopriv_(action)
为未登录的用户执行.如果您希望它在前端为访问者和登录用户触发,您可以这样做:
In WordPress,
wp_ajax_nopriv_(action)
executes for users that are not logged in.
if you want it to fire on the front-end for both visitors and logged-in users, you can do this:
add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );
所以在你的例子中像这样添加
So in your example add like this
add_action( 'wp_ajax_my_get_process_payment', 'get_process_payment' );
add_action( 'wp_ajax_nopriv_get_process_payment', 'get_process_payment' );
function get_process_payment(){
echo "test";
wp_die();
}
请查看https://codex.wordpress.org/AJAX_in_Plugins了解更多详情
这篇关于在 wordpress 插件中收到 400 个错误的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文