You’re not using wordpress default ajax mechanism.
To do that:
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php", // Send request to admin-ajax.php
data: newcontact, // Can be anything. As per your need
action: 'myaction', // Required to send otherwise WordPress AJAX won't authorize your request.
success: function(data) {
jQuery(".follow-user").html(data);
}
});
AJAX Request Handler
add_action( 'wp_ajax_myaction', 'so_wp_ajax_function' );
add_action( 'wp_ajax_nopriv_myaction' 'so_wp_ajax_function' );
function so_wp_ajax_function(){
//DO whatever you want with data posted
//To send back a response you have to echo the result!
echo $_POST['name'];
echo $_POST['age'];
wp_die(); // ajax call must die to avoid trailing 0 in your response
}
You can Refer WordPress Codex. http://codex.wordpress.org/AJAX_in_Plugins. It’s pretty well documented.
Here’s already answer question to your problem. i.e. https://stackoverflow.com/questions/17855846/using-ajax-in-a-wordpress-plugin