要执行服务器端->wordpress->php的“ShortCode”,通过JavaScript执行哪个客户端需要使用AJAX!
您可以使用以下内容:
1-在您的排队中。js文件:
jQuery(document).ready(function($) {
$(\'.buttonClass\').on(\'click\', function() {
$.ajax({
url: Param.doShortCode,
type: \'POST\',
data: {
action: \'handle_ajax_shortcode\',
},
success: function() {
//do something on success
},
error: function() {
//do something on error
}
})
})
});
2-在php文件中:
//localize your script
$Param = array(
\'doShortCode\'=>admin_url( \'admin-ajax.php?action=handle_ajax_shortcode\' ),
);
wp_localize_script(\'handle_ajax_shortcode\',\'Param\', $Param);
//executes for users that are not logged in.
add_action( \'wp_ajax_nopriv_handle_ajax_shortcode\', \'handle_ajax_shortcode\' );
//executes for users that are logged in.
add_action( \'wp_ajax_handle_ajax_shortcode\', \'handle_ajax_shortcode\' );
function handle_ajax_shortcode(){
//put whatever you want to be execute when JavaScript event is triggered
do_shortcode( string $content, bool $ignore_html = false )
// Don\'t forget to stop execution afterward.
wp_die();
}
有关更多信息,请查看
Link1 &;
Link2 &;
Link3