I want to tell my clients in México that we have a specialized website for them with a popup which has a link to the Mexican website. I dont know what is wrong or missing with the code. Any help is deeply appreciated
import { fetch } from ‘wix-fetch’ ;
import wixWindow from ‘wix-window’ ;
To add, since you’re working through multiple promises before you get to your final call, you might be better off using the async/await syntax, which will reformat your code to be easier to understand and less cluttered with callbacks. So in your case it would become:
import { fetch } from 'wix-fetch';
import wixWindow from 'wix-window';
const API_KEY = "aaabbb";
$w.onReady(async function () {
const httpResponse = await fetch(`https://extreme-ip-lookup.com/json/?key=${API_KEY}`, { method:'get'});
if (httpResponse.ok) {
const json = await httpResponse.json();
const loc = json.countryCode;
if(loc === 'MX') wixWindow.openLightbox("MexicoLightbox");
}
});
A couple of other things you can do :
Ensure that the API call is being correctly received by the Fetch function.