Нужна помощь с файлом Js. Я получил отзыв, что «В настоящее время .catch становится цепочкой для displayResults (ответ Json), что, вероятно, не то, что вы хотите здесь».
Результаты не добавляются. из функции displayResults и присоединения к странице searchForm.
Буду признателен за любые отзывы.
https://alyrlee.github.io/API-Hack-Capstone/
"use strict";
/*Foursqaure API Client Info
CLIENT_ID = '4UGIHJMXKJGHFPVDOKYYKM43JNHRNSUVMDG2MOEMKXHOTPYJ' //Foursquare ID
CLIENT_SECRET = 'YB1ZXEFPZNPPONALNV3PCQDOTNSRE3LW41KNPKPQG45SYXGK' //Foursquare Secret
VERSION = '20180323' //Foursquare API version
print('Your credentails:')
print('CLIENT_ID: ', CLIENT_ID)
print('CLIENT_SECRET:', CLIENT_SECRET)*/
const CLIENT_ID = '4UGIHJMXKJGHFPVDOKYYKM43JNHRNSUVMDG2MOEMKXHOTPYJ' //Foursquare ID
const CLIENT_SECRET = 'YB1ZXEFPZNPPONALNV3PCQDOTNSRE3LW41KNPKPQG45SYXGK' //Foursquare Secret
const VERSION = '20180323' //Foursquare API version
function watchForm() {
$('.searchForm').submit(function(event) {
event.preventDefault();
let city = $('#location').val();
getBusiness(city);
});
}
$(watchForm);
// Get Business Lists
function getBusiness(city) {
const url = `https://api.foursquare.com/v2/venues/search?near=${city}&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&v=${VERSION}`;
//Allow user must be able to set params
fetch(url)
.then((response) => {
if (response.ok) {
return response.json();
}
throw new Error(response.statusText);
})
.then(responseJson => displayResults(responseJson))
.catch(err => {
$('#error-message').text(`Something went wrong: ${err.message}`);
});
}
//Display business results
function displayResults(responseJson) {
console.log(responseJson);
$('#business-list').empty();
if (responseJson.length > 0) {
for (let i = 0; i < responseJson.data; i++) {
$('#business-list').append(`<li><a href="${responseJson[i].url}"${responseJson[i].city.name}${responseJson[i].venue.name}">${resposeJson[i].venue.location.address}</a></li>`);
};
} else {
$('#business-list').append("<li>Sorry, no results match your search</li>");
}
$('#searchForm').removeClass('hidden');
}
// BUSINESS_CATEGORY_ID = '4bf58dd8d48988d124941735'
//$('#result-title').text(`Places to connect around ${venueName}`);
//$('#results').text(`Click on the markers to see businesses in ${location}`);
//business_list = []
//googlePlacesAPI:
//'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=hybrid&key=AIzaSyDPpPhiwe2nBilWB_ihli85BlyRID4DnpU'
//map function
var map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 6
});
infoWindow = new google.maps.InfoWindow;
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
infoWindow.open(map);
}