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

ajax - wordpress and add actions to button by coding

programmeradmin3浏览0评论

I create my action in functions.php

add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
 function misha_filter_function()
 {
   echo "my button action"; 
 }

How can i create button to call this method wp_ajax_myfilter

I create my action in functions.php

add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
 function misha_filter_function()
 {
   echo "my button action"; 
 }

How can i create button to call this method wp_ajax_myfilter

Share Improve this question edited Apr 26, 2020 at 13:26 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Apr 26, 2020 at 12:41 Omnia MagdOmnia Magd 1151 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try below method.

<a id="view_site_description" href="javascript:void(0);">View Our Site Description</a>

add_action( 'wp_footer', 'add_js_to_wp_footer' );
function add_js_to_wp_footer(){ ?>
    <script type="text/javascript">
    jQuery('#view_site_description').click(function(){
        jQuery.ajax({
            type: 'POST',
            url: ajaxurl,
            data: {"action": "myfilter"},
            success: function(data){alert(data);}
        });
        return false;
    });
    </script>
<?php }
发布评论

评论列表(0)

  1. 暂无评论