最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

admin-ajax.php 400 bad request

programmeradmin5浏览0评论

I had created the ajax request

add_action('wp_ajax_test_action', 'test_action');

it works fine until some point

(Maybe i installed some plugin, but i had tried uninstall it but cant solve it)

So i try to add

add_action('wp_ajax_nopriv_test_action', 'test_action');

the request work again, but I don't understand

wp_ajax_nopriv suppose to work for the user not logged in

but i am a logged in user, I tried to logged out then login again, but still need to add "wp_ajax_nopriv" to make it work.

my js code:

//test ajax
$('button#test').on('click', function(e){
    e.preventDefault();
    console.log('click');
        $.ajax({
            url: $ajax_url,
            type: 'POST',
            data: {
                action: 'test_action',
                value: "send"
            },
            success: function(data){
                console.log( data);
            },
            error: function(data){
                console.log('error');
            }
        });

});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论