您应该使用WP推荐的默认方式来处理ajax调用。这将使您免于许多陷阱和不良做法。
add_action( \'wp_ajax_nopriv_****\', \'your_custom_function\' );
add_action( \'wp_ajax_****\', \'your_custom_function\' );
function your_custom_function() {
}
JS part
jQuery.ajax({
type: "post",
dataType: "json",
url: ajax_url,// need the admin_url(\'admin-ajax.php\')
data: formData, // your data
success: function(msg){
}
});
Additional context