Velo Code Stopped Working

Hi,

The velo code was working great until recently when it stopped working. I didn’t change the code but I added a store. I think it stopped working since I added the store. Any suggestions? Here’s the code.

import wixData from ‘wix-data’ ;
import { GetFXRates } from ‘backend/GetFXRates.jsw’ ;
import { getJSON } from ‘wix-fetch’ ;

const databaseName = ‘IVFPackagesbyCountry’ ;
const databaseField = ‘tags’ ;

// $w.onReady(function () {
// dataset1_ready();
// $w(‘#treatmentTags’).onChange((event) => {
// const selectedTag = $w(‘#treatmentTags’).value;
// addItemstoRepeater(selectedTag);
// })
// });

import wixLocation from ‘wix-location’ ;
import { fetch } from ‘wix-fetch’ ; $w . onReady ( function () { // Fetch the user’s location details
fetch ( ‘https://extreme-ip-lookup.com/json’ , {
method : ‘get’
}) // Check if the request was successful

. then (( httpResponse ) => { 
    if  ( httpResponse . ok ) { 
        **return**  httpResponse . json (); 
    } 
})      

. then (( json ) => { 
    // Set the user's countryCode as a const 
    const  loc  =  json . countryCode ;         /* Check if location is India, and check if the visitor is not on Pricing-in page */         
    console . log ( loc ); 
    if ( loc  ===  "GB" ){ 
        // Redirect to "pricing-in" page 
        wixLocation . to ( "/uk" ); 
        
        $w ( '#treatmentTags' ). onChange (( event ) => { 
            const  selectedTag  =  $w ( '#treatmentTags' ). value ; 
            addItemstoRepeater ( selectedTag ); 
        }) 

    } 
}); 

})

function addItemstoRepeater ( selectedOption = ) {

let  dataQuery  =  wixData . query ( databaseName ); 

if  ( selectedOption . length  >  0 ) { 
        dataQuery =  dataQuery . hasSome ( databaseField , selectedOption ); 
} 

dataQuery 
    . find () 
    . then ( results  => { 
        const  filtereditemsReady  =  results . items ; 
        $w ( '#packages' ). data  =  filtereditemsReady ; 

    }) 

}

@yisrael-wix perhaps you could help? thanks.

What is this code supposed to do? What isn’t it doing now? What changes were made? When did it stop working? Perhaps your changes broke something.

Please post your code, nicely formatted, in a code snippet block so we can more easily read it.

1 Like

Have you checked to see if: ‘https://extreme-ip-lookup.com/json’ still works?

I could be wrong but if httpResponse is !ok then

.then((httpResponse)=>{if(httpResponse.ok){returnhttpResponse.json();}})

Won’t ever resolve the promise, will it?? You don’t have a catch or else if for !httpResponse.ok

EDIT:

YUP! it’s not connecting:

This site can’t be reached

extreme-ip-lookup.com refused to connect.

Ok that might be it. Let me try to take it out. Thanks for checking.

I tried to use the ‘add a code snippet’ in this editor to format the code nicely but it doesnt seem to work.

SInce a couple of days, extreme-ip-lookup needs a KEY added to URL in order to work. Check their website.

Awesome! Thanks for pointing that out. That was it. I got it working now.