"Show the Local Weather Help" Need help please


#1

Need help on “Show the local weather” project


#2

Sorry, but your code is absolutely unreadable in this format. It’s always better to provide us with a link to your codepen.io, or any other website.

Heve you tried console.log(response) in your callback function?


#3

I just added a link as you have suggested.-Thanks


#4

I replaced the url in the Ajax call with

url: 'https://fcc-weather-api.glitch.me/api/current?lon='+position.coords.longitude+'&lat='+position.coords.latitude,

Then I replaced:

$("#c").text(response.city.name);

…with:

$("#c").text(response.name);

And it works.

There is no city property in the response. The name of the city is stored in response.name. I suggest outputting the response to the console like @N4thyra said next time you have a problem like this.


#5

That’s much better. It’s not just me who doesn’t like looking at such a HUGE chunk of code.

$.getJSON({
   url:'http//api.openweathermap.org/data/2.5/forecast?lat=34&lon=-84&appid=dd15e8ebfc2c02cf0af09be6ff83a252',//this http://code works from regular address line
  type: 'GET',
   dataType:'jsonp',
   success: function(response){
      //var myTemp = response.main.temp;
console.log(response.city.name);
   $("#c").text(response.city.name);//this does nto give any result
     $("#t").text(response.main.temp);//this does not give any results
 } //function response
              });//ajax
  1. try putting your URL into any browser, I guarantee you it is NOT going to work. It’s not a valid URL address. You’re missing the magic colon
  2. You’re using getJSON, but you’re using ajax syntax at the same time(I’m pretty new to ajax and stuff, and I may be wrong, but I doubt I am).

This is what, e.g. my getJSON function looks like:

  function getLocation() {
    $.getJSON(ipURL, coords => {
      let { latitude, longitude } = coords;
      console.log(latitude, longitude);
      let coordsURL= `lat=${latitude}&lon=${longitude}`;
      URL = `${apiURL}${coordsURL}&APPID=cfdc05d02854f871e2eae7e3a0988b1f&units=metric`;
      show();
    });
  }

ajax syntax:

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});

I highly recommend that you look for another api. I also used the one that you’re trying to use, and it sucks since you’re going to need to find a way to fix issues with security errors.

I used a proxy server in my project, so the URL address looks like this (not the best solution!!!)

https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?


#6

N4thyra and MatiasPi, Thanks for suggestions. I will change the source to get weather from https site instead of http://openweather and stick to .ajax since rest of the code is for that. I will let you know tomorrow about this. Again, thank you very much for your time and help.Goodnight.


#7

ajax/api/console problem

I can not get the output at console. Please help me to figure out what I’m doing wrong here. Thanks


#8

response doesn’t have a time property - otherwise seems to be working ok.


#9

Thanks, but unfortunatleyI deleted part of the code. I will re-type and check this out. My consol statement was
console.log(response.time);


#10

Can someone help me to find the problem with code. I had placed console.log along the way with comments about which one works. I do not know why some of the console.log does not work.
Here is my code…
https://codepen.io/dcpatel2815/pen/LjYRNV?editors=0011

Thank you very much.


#11

You have a function called getLocation(), but you never call it. To run it, you can a call to it like the following:

getLocation();

right before the following console.log():

console.log("before closing ready function"); //works