Hello
I’m stuck for several days at step 12 of wanderlust.
I had the following error: TypeError: NetworkError when attempting to fetch resource.
On the forum I saw that I had to add in the options object this property mode: ‘no-cors’.
I made this modification (but without really understanding why…)
Now I don’t have this error anymore, but the following one: Uncaught TypeError: r.contentDocument is null
When I display them on the console, I see response.ok = false
and for response this is what I get:
Response { type: “opaque”, url: “”, redirected: false, status: 0, ok: false, statusText: “”, headers: Headers, body: null, bodyUsed: false }
It seems to me though that I have done exactly what the first 12 steps require!
I’m really stuck, thanks in advance for your help!!!
Here is my code:
// Foursquare API Info
const foursquareKey = ‘XXXXXXXXXXXXXXXXXXXXXXXX’; // my foursquare API key
const url = ‘https://api.foursquare.com/v3/places/search?near=’;
// ajouter sample%20
// OpenWeather Info
const openWeatherKey = ‘XXXXXXXXXXXXXXXXXXXX’; // my OpenWeather API key
const weatherUrl = ‘https://api.openweathermap.org/data/2.5/weather’;
// Page Elements
const $input = $(’#city’);
const $submit = $(’#button’);
const $destination = $(’#destination’);
const $container = $(’.container’);
const $placeDivs = [$("#place1"), $("#place2"), $("#place3"), $("#place4")];
const $weatherDiv = $("#weather1");
const weekDays = [‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’];
const options = {
method: ‘GET’,
mode: ‘no-cors’, // added … is it right ??
headers: {
Accept: ‘application/json’,
Authorization: foursquareKey
}
};
// Add AJAX functions here:
const getPlaces = async () => {
console.log(‘entrée dans getPlaces’);
const city = $input.val();
const urlToFetch = ${url}${city}&limit=10
;
try {
const response = await fetch(urlToFetch,options);
if (response.ok){}
console.log(‘response.ok=’,response.ok);
console.log(‘response =’,response);
}catch (error) {console.log(error);}
};
const getForecast = () => {
};
(…)