Hello guys! I’m new here, I have followed every single detail from this tutorial , and it is not working, so I need to autofill City and State fields based on zip code input, please help me.
This is my code, When I Typing the zip code, absolutely nothing happens, maybe something is missing in the onReady function?
Any suggestion is really appreciated.
.
$w.onReady(function () {
// Write your JavaScript here
}
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:
//cuando el usurio escriba e un campo este codigo se ejecutara
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("El codigo postal no fue encontrado");
}
} )
.then ( (json) => {
console.log(JSON.stringify(json));
$w("#city").value = json.city;
$w("#state").value=json.state;
} )
.catch ( (err) => {
console.log(err);
} );
}
}