1

This is the link to my codepen: http://codepen.io/dsemel/pen/VamEyE

This is the section of code that seems to be the problem:

function success(position){

var WeatherKey = '6068dffce2f44535a07202457162103';

var lat = position.coords.latitude; 

var long = position.coords.longitude; 



   var weatherUrl = "http://api.apixu.com/v1/current.json?key=" + WeatherKey +     
                     "&q=" + lat + "," + long;



$.ajax({
url : weatherUrl,
type: 'GET',
dataType : 'json',
success : function(data) {
var city = data['location']['name'];
    var tempFar = data['current']['temp_f'];
    var img = data['condition'][0]['icon'];

    var desc = data['condition']['text'];

$('#weatherInfo2').text(tempFar);  
}

 });
}
1
  • The tempFar data will not display on the page. Commented Mar 26, 2016 at 0:32

2 Answers 2

1

Make sure you check your developer tools console when you encounter these errors. Your code is throwing this error Uncaught TypeError: Cannot read property '0' of undefined.

The condition object is part of the current object, therefore you have to access the current object before accessing the condition object.

Updated working codepen

Sign up to request clarification or add additional context in comments.

Comments

0

I think your code works fine you just missed a small thing in your code i corrected that http://codepen.io/rahulchaturvedie/pen/RagGdR

$.ajax({
  url : weatherUrl,
  type: 'GET',
  dataType : 'json',
  success : function(data) {
    console.log(data);
    var city = data['location']['name'];
    var tempFar = data['current']['temp_f'];
    var img = data.current.condition.icon; // correct this
    var desc = data.current.condition.text; // correct this
    $('#weatherInfo2').text(tempFar);  
   }   
  });

1 Comment

i am glad i could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.