질문은 매우 명확하지 않다, 그러나 나는 모두가 기록과 비는 로그인 한 사용자를 위해 당신이 AJAX 작업을 추가하는 데 도움이됩니다. 지금은
// Add this to functions.php
// Let's enqueue our javascript file
function include_ajax_js() {
wp_register_script(
'ajax-custom-script',
get_stylesheet_directory_uri() . '/js/ajax.js',
array('jquery')
);
// Add data your script that you can normally
// only get from the server side of WordPress.
$localize = array(
'ajaxurl' => admin_url('admin-ajax.php'),
// Securing your WordPress plugin AJAX calls using nonces
'auth' => wp_create_nonce('_check__ajax_100')
);
wp_localize_script('ajax-custom-script', 'custom_ajax_vars', $localize);
wp_enqueue_script('ajax-custom-script');
}
add_action('wp_enqueue_scripts', 'theme_name_scripts');
// Let's make function to handle AJAX requests
function my_ajax_action() {
// Check nonce
check_ajax_referer('_check__ajax_100', 'nonce_field');
// Let's display some useful information
// May be you need to check if the user is still logged in
$user_greeting = is_user_logged_in() ? 'Hello User !' : 'Hello Guest !';
$data = array('msg' => $user_status);
echo json_encode($data); // encode the output to JSON
die();
}
add_action('wp_ajax_check_status', 'my_ajax_action');
// wp_ajax_nopriv_ executes for users that are not logged in
add_action('wp_ajax_nopriv_check_status', 'my_ajax_action');
충분히 PHP,의는은 ajax.js
jQuery(document).ready(function(){
jQuery.ajax({
type:"POST",
// We can easily get the AJAX Url from the object we've created before
url: custom_ajax_vars.ajaxurl,
// Data should be sent as an object
data: { action: check_status, nonce_field: custom_ajax_vars.nonce },
success:function(data){
alert(data.status);
}
)}
})
})
무슨 당신의 목표를 만들 수? 로그인 후 데이터를 가져 오시겠습니까? –
아니요, 자동 응답하지 않고 아약스 요청을 원합니다. –
권한없이 데이터를 넣으시겠습니까? –