您需要通过ajax请求发送var:
$.post(
//be suer that this var is pointing to wp-admin/admin-ajax.php
WPaAjax.ajaxurl,
{
action : \'my_php_action_to_do\',
//here your var and its value
my_var : \'the_value\'
},
function( response ) {
response = jQuery.parseJSON(response);
alert(response.message);
}
);
在my\\u php\\u action\\u to\\u do函数中:
function my_php_action_to_do(){
$var[\'message\'] = $_POST[\'my_var\'];
//Send back the $var value in json format. You can send it in other format if you want
echo json_encode( $var );
exit();
}
//Don\'t forget to add your my_php_action_to_do function to wp_ajax_* action hook.
add_action(\'wp_ajax_my_php_action_to_do\', \'my_php_action_to_do\');
//or this if you want it to work in the frontend
add_action(\'wp_ajax_nopriv_my_php_action_to_do\', \'my_php_action_to_do\');