Hello Reader's if you want to write a custom code for making AJAX hit then you should choose for the best path for that, Open the file admin-ajax.php All ajax request should be made there.
On in first step open the template file and write the code below:-
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
Now open the Javascript File and wite the code below:-
$.ajax({
url: ajaxurl,
type: "POST",
cache: false,
data: data + '&action=sendmail' // or you can define the function
});
Now open the function.php file and make this function:-
function send_my_mail(){
#do your stuff
}
add_action('wp_ajax_sendmail', 'send_my_mail');
add_action('wp_ajax_nopriv_sendmail', 'send_my_mail');
0 Comment(s)