The most common method to use AJAX in WordPress is using admin-ajax.php + WordPress hook system.
And one of the recommended method to get this file URL is by using wp_localize_script()
. This method is explained in details in my other tutorial WordPress AJAX for Beginners.
However, there is an alternative method.
Read More You Don’t Need “wp_localize_script()” to Get “admin-ajax.php”