Calling Ajax In WordPress

Here is the code for calling ajax functions in WordPress.

//javascript function
function test()
var sitename = "http://localhost/test/"; //getdynamic
var ajax_path = "/wp-admin/admin-ajax.php";
var name=$('#name').val();
var cell='9999999999';
type : "POST",
async : false,
url : sitename + ajax_path,
data : {
action : 'printmyName', //function name
namevar: name, //variable to send
cellvar:cell //variable to send
}).done(function(msg) {

}); // ajax close


//function.php code
add_action('wp_ajax_CurrentServerTime', 'CurrentServerTime');
add_action('wp_ajax_nopriv_CurrentServerTime', 'CurrentServerTime');
function printmyName()
echo "My name is ".$name." and number is ".$cellvar;