在函数中编写以下代码。活动主题的php
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
\'action\': \'get_data\',
\'testparam\':\'hello\' //optional to pass any extra param
};
$.ajax(ajaxurl, data, function(response) {
alert(\'Response: \' + response);
//Append response in your result wrapper
});
});
</script>
<?php
add_action( \'wp_ajax_get_data\', \'get_data_ajax_func\' );
function get_data_ajax_func() {
global $wpdb;
$param = $_POST[\'testparam\'] ;
$html = "result"; // get data from database
echo $html; //return result
exit();
}
?>
Firebug ajax请求检查其工作情况!希望这会有帮助!