Trouble displaying data from ajax json parse

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);  
}

 });
}

Answers 1

  • 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);  
       }   
      });
    

Related Articles