<?php
add_action('wp_ajax_my_action', 'my_action_callback');
function my_action_callback() {
	global $wpdb; // this is how you get access to the database
	$name = $_POST['name'];
	echo 'Hello, '.$name;
	die(); // this is required to return a proper result
}

add_action('wp_print_footer_scripts', 'my_action_javascript');

function my_action_javascript() {
?>
<script type="text/javascript" >
	var ajaxurl='<?php echo get_site_url(); ?>/wp-admin/admin-ajax.php';
jQuery(document).ready(function($) {
	var myname=prompt('Enter your name','');
	var data = {
		action: 'my_action',
		name: myname
	};
	jQuery.post(ajaxurl, data, function(response) {
		alert('Server response: ' + response);
	});
});
</script>
<?php
}
?>