Hi I am trying to use Ziptastic API to autofill the City and State info in the user input form and using the below code. But it’s always going to “Fetch did not succeed”. Please help
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import {
fetch
} from ‘wix-fetch’;
$w.onReady( function () {
//TODO: write your page related code here…
});
export function input4_keyPress(event) {
//Add your code for this event here:
let zipcode = $w(“#input4”).value;
let apiUrl = “http://ZiptasticAPI.com/”;
if (zipcode.length === 5) {
fetch(apiUrl + zipcode, {
“method”: “get”
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject(“Fetch did not succeed”);
}
})
.then((json) => {
console.log(JSON.stringify(json));
$w(“#input5”).value = json.city;
$w(“#input6”).value = json.state;
})
. catch (err => console.log(err));
}
}