Please try this code :
Add this code in your function.php file
function AjaxCallBack()
{
foreach($_POST as $key=>$value)
$$key = $value;
//Email script will go here!
die();
}
// creating Ajax call for WordPress
add_action('wp_ajax_nopriv_MyAjaxCallBack', 'AjaxCallBack');
add_action('wp_ajax_AjaxCallBack', 'AjaxCallBack');
And Add this code in your header.php or footer.php
jQuery(document).ready(function() {
jQuery("#PleasePushhere").click(function(){ //PleasePushhere this is your html form id
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php');?>',
data: {
action: 'MyAjaxCallBack',
MyParam: 'MyParamValue'
},
success: function(data, textStatus, XMLHttpRequest){
alert(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});
I hope this is helps you.
Thank you.
Best way to implement Ajax in WordPress is to use admin-ajax.php
In your functions.php of your template add following code
function MyAjaxCallBack()
{
foreach($_POST as $key=>$value)
$$key = $value;
//Email script will go here!
die();
}
// creating Ajax call for WordPress
add_action('wp_ajax_nopriv_MyAjaxCallBack', 'MyAjaxCallBack');
add_action('wp_ajax_MyAjaxCallBack', 'MyAjaxCallBack');
Ajax script (Add it to header.php or footer.php):
jQuery(document).ready(function() {
jQuery("#PleasePushMe").click(function(){
jQuery.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php');?>',
data: {
action: 'MyAjaxCallBack',
MyParam: 'MyParamValue'
},
success: function(data, textStatus, XMLHttpRequest){
alert(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});