Ajax : Why success displays 0?

前端 未结 10 1212
生来不讨喜
生来不讨喜 2021-01-01 19:02

I use ajax with jquery and when I tried to display the result in popup. Then alert always displays 0

success : function(results) { 
alert(result         


        
10条回答
  •  佛祖请我去吃肉
    2021-01-01 19:30

    I was adding the "action" incorrectly. You have to prefix your action with wp_ajax_gd_.

    add_action('wp_ajax_gd_[ACTION NAME]', '[CALLBACK FUNCTION NAME]')
    

    and in the JS jQuery post:

    var data = {
        'action': '[ACTION NAME]',
    };
    

    I found Wordpress' documentation very unclear about this part.

提交回复
热议问题