No need to use AJAX.
In your PHP:
$_SERVER['REMOTE_ADDR']
That’s the connected client’s IP, assuming they’re not using a Proxy and whatnot.
Add this IP to a variable in your script if you need to use it in your JS.
5
solved How to get Client Ip address in Javascript and jQuery? [duplicate]