How to call Ajax in wordpress in custom.php page?

Solution:

Thank you so much the problem is solved

i had to put the current main url ( domain/ subdomain ) without any slugs

so the best solution for this case is use this url :

var ajaxurl = "https://<?php echo $_SERVER['HTTP_HOST'];?>/wp-admin/admin-ajax.php";

Answer

Solution:

You need to use wp_localize_script in order to have access to ajaxurl global. If you don't want to do that then you can replace ajaxurl with <?php echo admin_url('admin-ajax.php');?> if you javascript is inside a PHP file.

Source