Your have to use full url of ajax function. I have use ajax_url
in your Ajax Call – footer.php(theme footer) file code.
<script>
var ajax_url = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
jQuery(function() {
jQuery("#calc_form").on("submit", function(e) {
// alert("submit");
e.preventDefault();
jQuery.ajax({
method: "POST",
url: ajax_url,
data: {
action: 'calculation',
message_id: jQuery('#tot_tax_three_month_Input').val()
},
dataType: 'json',
success: function (output) {
}
});
});
});
</script>
Remove code from wp-admin->admin-ajax.php file and Add that code in your active theme’s functions.php file instead of wp-admin->admin-ajax.php
// handle the ajax request
function calculation() {
$value = $_REQUEST['message_id'];
echo json_encode(array("value" => $value));
die();
}
// register the ajax action for authenticated users
add_action('wp_ajax_calculation', 'calculation');
// register the ajax action for unauthenticated users
add_action('wp_ajax_nopriv_calculation', 'calculation');