(Solved)Stuck on WeatherApp, API issues

I seem to be running around in circles with this API for the WeatherApp. So far I have read the forum for this and looked at the code of others, but for some reason it is not pulling data back to my pen. Can I get some feedback on what I could possibly be missing.

  • I added a proxy, thinking that is it?
  • I am using geoloaction with lat and lon as a variable (does it matter how long the coordinate is)
  • I’ve tried ajax and JSON
  • I’ve tired multiple weather APIs

Thank you.

Calling the URL directly I am getting
Missing required request header. Must specify one of: origin,x-requested-with
Did you use the proxy correctly?

You don’t need the proxy. To start getting a response back from the API, you just need to do two things:

  1. change your http:// to https:// in your url so you would use the following :slight_smile:
var api = url + "lat=" + lat + "&lon=" + lon + "&APPID=" + key;

Also, you need to actually call the getWeather funciton like so:


As well as what @RandellDawson said, changing the api call to https:// works:

I’ve changed url to include the ‘s’ and removed the proxy, but am still getting nothing.

Are you still using the same codepen as you were before? If so, you must not have seen my second comment (shown below) in my first response.

ahh, hmm, so new to this, how/where would I add that?

If you have completed all the basic JS and Basic Algorithms, I would think you would know where to call the function. In case you want to try on your own first, I have blurred out where to put the call to the function below. Don’t click on the blur unless you really don’t want to figure it out by yourself.

var api = url+"lat="+lat+"&lon="+lon+"&APPID="+key;

That’s perfect thank you so much. I am going to revisit those right now. See if I can figure it out and I just am having brain over load right now from banging my head over this API stuff. Thank you so much. I’ll let you know once I figure it out (hopefully without looking at your blurred out section).

Thank you again Randell, I just looked at “Write Reusable JavaScript with Functions” under the JS and had an ‘ahh ha’ moment. I didn’t even need to look at the blurred out answer you provided. The API is now pulling the information I need. Thank you thank you.