我正在研究wordpress, Ajax请求:
$(function(){
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
var data = {'action': 'weatherblock', 'weather_id': '<?=$weather_id?>'};
$.post( ajaxurl, data, function( response ) {
$('.weather_block_page').html(response);
console.log(response);
});
});
更新:(但此变体仍为0)
$.ajax({
url: ajaxurl,
method: "POST",
data: { 'action': 'weatherblock', 'weather_id': '<?=$weather_id?>' },
dataType: "json",
success: function(data) {
console.log(data);
}
});
php方面:
function weatherblock_func(){
echo 'test';
die();
}
add_action('wp_ajax_weatherblock', 'weatherblock_func');
add_action('wp_ajax_nopriv_weatherblock', 'weatherblock_func');
在控制台中,我得到0,为什么?