What's wrong with this fetch request?
up vote
-1
down vote
favorite
let path=`api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey= `&APPID=758bab291826491e79f93979de2ba255`
let url= path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
im getting this in the console
I cant figure it out, i'm very new to this. Its saying 404 but if I copy the URL and go to it it shows the JSON data
err after adding https://
ajax fetch
add a comment |
up vote
-1
down vote
favorite
let path=`api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey= `&APPID=758bab291826491e79f93979de2ba255`
let url= path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
im getting this in the console
I cant figure it out, i'm very new to this. Its saying 404 but if I copy the URL and go to it it shows the JSON data
err after adding https://
ajax fetch
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
let path=`api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey= `&APPID=758bab291826491e79f93979de2ba255`
let url= path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
im getting this in the console
I cant figure it out, i'm very new to this. Its saying 404 but if I copy the URL and go to it it shows the JSON data
err after adding https://
ajax fetch
let path=`api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey= `&APPID=758bab291826491e79f93979de2ba255`
let url= path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
im getting this in the console
I cant figure it out, i'm very new to this. Its saying 404 but if I copy the URL and go to it it shows the JSON data
err after adding https://
ajax fetch
ajax fetch
edited Nov 8 at 20:26
asked Nov 8 at 19:14
user10278089
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
this should do the trick:
let path = `https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey = `&APPID=758bab291826491e79f93979de2ba255`;
let targetURL = path + apiKey;
function getWeather(url)
return fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err));
getWeather(targetURL);
so there are 2 problems with your initial question:
- when you do a fetch it tries to do the fetch from the domain the the
app is currently in. Which is why you're getting 127.0.0.1:5000
(localhost), if you supply https:// it should not do that. - you were not passing in the url to the getWeather(url) function that
you had declared. Hope this helps!
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
add a comment |
up vote
0
down vote
try this instead:
let path=`https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey=`&APPID=758bab291826491e79f93979de2ba255`
let url=path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
This should work. why? Because when you do a fetch it tries to do the fetch from the domain the the app is currently in. Which is why you're getting 127.0.0.1:5000 (localhost), if you supply https:// it should not do that.
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
this should do the trick:
let path = `https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey = `&APPID=758bab291826491e79f93979de2ba255`;
let targetURL = path + apiKey;
function getWeather(url)
return fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err));
getWeather(targetURL);
so there are 2 problems with your initial question:
- when you do a fetch it tries to do the fetch from the domain the the
app is currently in. Which is why you're getting 127.0.0.1:5000
(localhost), if you supply https:// it should not do that. - you were not passing in the url to the getWeather(url) function that
you had declared. Hope this helps!
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
add a comment |
up vote
0
down vote
accepted
this should do the trick:
let path = `https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey = `&APPID=758bab291826491e79f93979de2ba255`;
let targetURL = path + apiKey;
function getWeather(url)
return fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err));
getWeather(targetURL);
so there are 2 problems with your initial question:
- when you do a fetch it tries to do the fetch from the domain the the
app is currently in. Which is why you're getting 127.0.0.1:5000
(localhost), if you supply https:// it should not do that. - you were not passing in the url to the getWeather(url) function that
you had declared. Hope this helps!
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
this should do the trick:
let path = `https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey = `&APPID=758bab291826491e79f93979de2ba255`;
let targetURL = path + apiKey;
function getWeather(url)
return fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err));
getWeather(targetURL);
so there are 2 problems with your initial question:
- when you do a fetch it tries to do the fetch from the domain the the
app is currently in. Which is why you're getting 127.0.0.1:5000
(localhost), if you supply https:// it should not do that. - you were not passing in the url to the getWeather(url) function that
you had declared. Hope this helps!
this should do the trick:
let path = `https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey = `&APPID=758bab291826491e79f93979de2ba255`;
let targetURL = path + apiKey;
function getWeather(url)
return fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err));
getWeather(targetURL);
so there are 2 problems with your initial question:
- when you do a fetch it tries to do the fetch from the domain the the
app is currently in. Which is why you're getting 127.0.0.1:5000
(localhost), if you supply https:// it should not do that. - you were not passing in the url to the getWeather(url) function that
you had declared. Hope this helps!
edited Nov 8 at 20:42
answered Nov 8 at 20:33
Matt Pengelly
458316
458316
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
add a comment |
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
Thanks so much, would you mind explaining where i went wrong?
– user10278089
Nov 8 at 20:35
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
i edited the answer above. There were 2 issues :). you can still do the path + url like you had before as well. that wasnt part of the issue.
– Matt Pengelly
Nov 8 at 20:37
1
1
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
ill edit the answer again so that it reflect more what you had originally wwrote. i simply had simplified the original problem to make understanding the problem easier for myself. just a minute and you should see a new edit.
– Matt Pengelly
Nov 8 at 20:39
1
1
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
the new edit is very close to what you originally had except with the 2 small fixes needed!
– Matt Pengelly
Nov 8 at 20:41
add a comment |
up vote
0
down vote
try this instead:
let path=`https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey=`&APPID=758bab291826491e79f93979de2ba255`
let url=path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
This should work. why? Because when you do a fetch it tries to do the fetch from the domain the the app is currently in. Which is why you're getting 127.0.0.1:5000 (localhost), if you supply https:// it should not do that.
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
add a comment |
up vote
0
down vote
try this instead:
let path=`https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey=`&APPID=758bab291826491e79f93979de2ba255`
let url=path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
This should work. why? Because when you do a fetch it tries to do the fetch from the domain the the app is currently in. Which is why you're getting 127.0.0.1:5000 (localhost), if you supply https:// it should not do that.
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
add a comment |
up vote
0
down vote
up vote
0
down vote
try this instead:
let path=`https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey=`&APPID=758bab291826491e79f93979de2ba255`
let url=path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
This should work. why? Because when you do a fetch it tries to do the fetch from the domain the the app is currently in. Which is why you're getting 127.0.0.1:5000 (localhost), if you supply https:// it should not do that.
try this instead:
let path=`https://api.openweathermap.org/data/2.5/weather?q=London`;
let apiKey=`&APPID=758bab291826491e79f93979de2ba255`
let url=path+apiKey;
function getWeather(url)
return fetch(url)
.then(response=> response.json())
.then(data=>console.log(data))
.catch(err=> console.log(err))
getWeather();
This should work. why? Because when you do a fetch it tries to do the fetch from the domain the the app is currently in. Which is why you're getting 127.0.0.1:5000 (localhost), if you supply https:// it should not do that.
answered Nov 8 at 20:00
Matt Pengelly
458316
458316
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
add a comment |
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
Still isnt working
– user10278089
Nov 8 at 20:16
Still isnt working
– user10278089
Nov 8 at 20:16
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
what does the GET in the console show now for the url?
– Matt Pengelly
Nov 8 at 20:17
added photo to post
– user10278089
Nov 8 at 20:26
added photo to post
– user10278089
Nov 8 at 20:26
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
sorry about that i submitted a different answer and it works in my browser now. so that other answer should work for you.
– Matt Pengelly
Nov 8 at 20:33
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214658%2fwhats-wrong-with-this-fetch-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown