How to call ajax in wordpress

后端 未结 7 529
青春惊慌失措
青春惊慌失措 2020-11-28 10:49

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 = \'         


        
7条回答
  •  盖世英雄少女心
    2020-11-28 11:14

    If you are getting 0 in the response, it means your ajax call is working correctly. But, you have not defined $wpdb as a global variable in your function get_data. Check your error log, you must be seeing error there. Try:

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

提交回复
热议问题