Sending an AJAX request to a specific file is not the way to do AJAX in WordPress. This is because WordPress itself is not loaded by your file, so you wouldn’t be able to use WordPress functions without an error.
There are two proper ways to handle AJAX requests in WordPress:
- Using the
wp_ajax_
hooks: https://developer.wordpress.org/plugins/javascript/enqueuing/#ajax-action - Creating a custom REST API endpoint: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/