Write below code in functions.php of your active theme
<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 the ajax request to check its working!
Hope it will help!