0

In a plugin, I am initiating an ajax script:

function getthatable_callback() {

global $wpdb; 
include("phpscripts/gettable.php");
    wp_die(); 
}

add_action( 'wp_ajax_getthatable', 'getthatable_callback' ); 
add_action( 'wp_ajax_nopriv_getthatable', 'getthatable_callback' );

In phpscripts/gettable.php, I try

print_r(wp_get_current_user());

I call the ajax script like this:

jQuery.post(ajaxurl, {'action':'getthatable'}, function(data){
 jQuery("#thatablecont").html(data);
});

I use Q-translate-X and have a multilingual option set to en.mydomain.com. The AJAX script, when I access the site as en.mydomain.com, outputs an empty object:

WP_User Object ( [data] => stdClass Object ( ) [ID] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [filter] => )

But when I access it from mydomain.com, it shows well the logged-in user.

Thanks for help!

4

1 回答 1

1

错误在于我的 js 中预设的 ajaxurl。一个快速的解决方法是手动重置它:

var ajaxurl=location.protocol + "//" + document.domain + "/wp-admin/admin-ajax.php";
于 2017-01-12T17:28:01.037 回答