I'm trying to take an address in Forms and look-up the census tract data from the census.gov API.
I can get this to work by just putting the URL into a browser:
https://geocoding.geo.census.gov/geocoder/geographies/address?street=2687+West+7800+South&city=West+Jordan&state=UT&benchmark=Public_AR_Census2010&vintage=Census2010_Census2010&layers=14&format=json
This returns the values for my work address.
But I cannot get this to work via Javascript in LFForms:
$('#testbutton').click(function(){
var url = new URL('https://geocoding.geo.census.gov/geocoder/geographies/address')
var params = [['street', '2687+West+7800+South'], ['city', 'West+Jordan'], ['state', 'UT'], ['benchmark', 'Public_AR_Census2010'], ['vintage', 'Census2010_Census2010'], ['layers', '14'], ['format', 'json']]
url.search = new URLSearchParams(params)
fetch(url, {mode: "no-cors"})
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(JSON.stringify(myJson));
});
});
This is what I get in the console when I click the "#testbutton":
Does anyone have any experience with this kind of stuff and could give me some guidance?