WP表单处理程序不是由POST触发的

I have a piece of code that is not working. It is a handler for POST submission. Below is the code sending data.

$.ajax({
  type: 'POST',
  url: '/calculator.php',
  data: $('form').serialize(),
  success: function(data) {
    console.log(data);
  }
});

The handler - calculator.php looks like:

<?php
$parse_url = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
require_once($parse_url[0], 'wp-load');
send_email();
echo 'success';

function sendEmail() {
  ..
  wp_mail($to, $subject, $message, $headers);
}
?>

When calculator.phps is being invoked from the command line, it works fine. However, submitting the from with ajax or postman does nothing. I have a varnish cache in front of my server, but it should not matter. Should it?

Put the calculator.php file in the root of the wordpress installation with the following changes. and use this path as your ajax url

calculator.php

<?php
require_once('wp-load.php');
send_email();
echo 'success';

function sendEmail() {
  ..
  wp_mail($to, $subject, $message, $headers);
}
?>