Use admin-ajax.php instead of self made ajax endpoint.