How to call ajax in wordpress

My ajax call output is always showing 0 as output don’t know why

In functions.php I have this code

function get_data() {
    $abc = '1';
    $result = $wpdb->get_results("SELECT * FROM ".$wpdb->options ." WHERE option_name LIKE '_transient_%'");
    echo  $result; //returning this value but still shows 0


add_action( 'wp_ajax_nopriv_get_data', 'get_data' );
add_action( 'wp_ajax_get_data', 'get_data' );

And my ajax call is in a javascript

$('body').on("click", ".re-reset-btn", function(e){

        var panel = $('#re-compare-bar');       

                 type : "GET",
                 dataType : "json",
                 url : "/wp-admin/admin-ajax.php",
                 data : {action: "get_data"},
                 success: function(response) {

                       alert("Your vote could not be added");

        $("#re-compare-bar-tabs div").remove(); 
        $('.re-compare-icon-toggle .re-compare-notice').text(0); 


I’m making ajax call in wordpress without use of plugin but not getting what I’m passing.Even If I output $abc still it shows 0.

Read more here: How to call ajax in wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *