Wordpress AJAX doesn't work - response 0

后端 未结 3 1935
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 11:37

I want add AJAX support to my plugin and I have huge problem with this simple thing. WordPress isn\'t permitting me to use normal AJAX and I need to use WordPress version.

3条回答
  •  遇见更好的自我
    2021-01-21 12:26

    I see few problems here. Action should inside the data object, not as a jQuery Ajax parameter. Also in the callback function data is stored in $_POST variable.

    function test_callback() {
    
        $whatever = $_POST['whatever'];
        echo $whatever;
    
        die();
    }
    add_action('wp_ajax_nopriv_fqtag', 'test_callback');
    add_action('wp_ajax_fqtag', 'test_callback');
    
    function print_js() {
        ?>
        
        
    

提交回复
热议问题