您可以使用wp\\U ajax操作:
add_action( \'wp_ajax_my_awesome_ajax\', \'my_awesome_func\' );
add_action( \'wp_ajax_nopriv_my_awesome_ajax\', \'my_awesome_func\' );
function my_awesome_func() {
// Handle request with $_POST
wp_die();
}
您可以使用jQuery post提交联系表单:
jQuery.post(
my_awesome_js.ajaxurl,
{
\'action\': \'my_awesome_ajax\',
\'data\': \'some data\'
},
function(response){
alert(response);
}
);
my\\u awesome\\u js。ajaxurl您使用的wp\\u localize\\u脚本:
wp_enqueue_script(\'my_awesome_js\', \'/path/to/your/script/above.js\', array(\'jquery\'));
wp_localize_script(\'my_awesome_js\', \'my_awesome_js\', array(
\'ajaxurl\' => admin_url(\'admin-ajax.php\')
));