Why is my ajax request getting response 0?

后端 未结 3 1725
既然无缘
既然无缘 2020-12-10 04:14

I\'ve setup the basic wordpress ajax example in my wp theme. The trigger is made by modernizr.js checking the media queries on the page.

jQuery(document).rea         


        
3条回答
  •  没有蜡笔的小新
    2020-12-10 04:59

    Everything has to match here:

    PHP

    add_action('wp_ajax_my_action',        'my_action');
    add_action('wp_ajax_nopriv_my_action', 'my_action');
    
    function my_action() {}
    

    JS

    var data = {
        action: 'my_action',
        whatever: ajax_object.we_value 
    };
    

    Also, you're missing security checks and a better handling of the response.
    Check this examples: [ 1 ] and [ 2 ].

提交回复
热议问题