Hello guys, I’m having a issues using this code based on this tutorial , It doesn’t work for me and I don’t know what is the problem, I have tested the API on this website and there is no problem with the API. I would like to know if I’m implementing something wrong, please anyone who can help me?
$w.onReady(function () {
// Write your JavaScript here
$w("#zipcode").onChange( (event) => {
zipcode_keyPress(event);
});
}
export function zipcode_keyPress(event, $w) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
//
let zipcode = $w("#zipcode").value;
let apiURL = "http://ZiptasticAPI. com/";
if (zipcode.lenght === 5) {
fetch(apiURL + zipcode, {nethod: "get"})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.jason();
}
else{
return Promise.reject("error");
}
} )
.then ( (json) => {
console.log(JSON.stringify(json));
$w("#city").value = json.city;
$w("#state").value=json.state;
} )
.catch ( (err) => {
console.log(err);
} );
}
}