I would not try to use this client side, I would use a network network balancer or some other virtual IP address on the server side.
Client-side requests require that your AJAX calls be made in such a way as to avoid browser protection or fully comply with cross-domain requests. If you are happy to make these changes, that is, some DNS JavaScript libraries, they can be used to resolve the DNS name to an IP address or CName, use the returned IP address or CName to configure your AJAX URL, and update the AJAX url using New DNS lookup when AJAX call fails.
I wouldn’t want to do it myself
source share