Hello everyone, I want to show the IP address of the user on a page.
I tried everything to get it, but when I ask for it with an external api, the ip is undefined:
Hello - using extreme-ip-lookup, our site is able to display the visitor’s city name but that text disappears immediately. This didn’t used to happen before, and I haven’t touched the code from last time. Any change in wix code causing this?
this is my code:
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import {
fetch
}
from ‘wix-fetch’ ;
$w . onReady ( function () {
fetch ( 'https://extreme-ip-lookup.com/json' , {
method : 'get'
})
. then (( httpResponse ) => {
if ( httpResponse . ok ) {
**return** httpResponse . json ();
}
})
. then (( json ) => {
const ipaddress = json . query ;
let city = json . city ;
if ( city !== **null** && city !== '' )
{
$w ( "#text43" ). text = city ; //set city name for text27 in frontend.
}
**else**
{
//return '';
$w ( "#text43" ). text = "" ; //set city name is blank or null then it will show blank.
}
// return ipaddress;
});
});
export function text43_viewportEnter ( event ) {
//Add your code for this event here:
}
Dealing with APIs can be tricky sometimes, especially when it comes to getting user IP addresses.
Reminds me of a similar situation I faced when I was setting up a website. I struggled to retrieve user IPs until I found a reliable booter service that provided accurate data without any hiccups.
So, don’t give up just yet! Keep exploring different approaches, and you’ll eventually find the solution that works best for you. Good luck!