I'm currently working on an autocomplete form that automatically populates the location field based on the user's zipcode. Below is the code snippet I've written to retrieve a JSON object containing location information using the provided zipcode:
var client = new XMLHttpRequest();
client.open("GET", "http://api.zippopotam.us/nl/1012", true);
client.onreadystatechange = function() {
if(client.readyState == 4) {
// alert(client.responseText);
var jsonObj = [client.responseText]
};
};
client.send();
My challenge now is to extract only the location data from the JSON response and store it in a variable. What I want to achieve is something like this:
var location = 'Amsterdam'
Any suggestions or tips would be greatly appreciated. Thank you!