ini_set('display_errors',1);
header("Access-Control-Allow-Origin: *");
function tell_me() {
$data = array();
$count = 0;
for($i = 95; $i < 90; $i++){
$data[$count]['name'] = get_post_meta($i,'name',true);
$data[$count]['lat'] = get_post_meta($i,'lat',true);
$data[$count]['lng'] = get_post_meta($i,'lng',true);
$count++;
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die();
}
add_action('wp_ajax_tell_me', 'tell_me',1); // ログイン状態のユーザーからのアクセスで動作する
add_action('wp_ajax_nopriv_tell_me', 'tell_me',1); // 非ログインのユーザーからのアクセスで動作する
サーバーのadmin-ajaxにこんなファイルを置いて、クライアント側で
jQuery(function ($) {
$.ajax({
crossDomain: true,
type: "POST",
url: wp_url_admin_ajax,
data: {
action: "tell_me"
},
success: function (response) {
alert("成功");
}
});
});
を実行したところ、成功のアラートボックスが表示された。


