Search code examples
jqueryyahoo-weather-api

JQuery 3.x Object doesn't support property or method 'success'


I am using the Yahoo Weather API. It works fine with JQuery 1.x. The issue is with JQuery 3.x. I am getting this error: Object doesn't support property or method 'success'. What can I use instead of .success?

I tried .done based on the documentation but it does not show any data.

https://api.jquery.com/deferred.done/

$(document).ready(function(){
  var city = "Erie, PA";
  var searchtext = "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city + "') and u='f'"
  $.getJSON("https://query.yahooapis.com/v1/public/yql?q=" + searchtext + "&format=json").success(function(data){
      $('#weather-temp').html(data.query.results.channel.item.condition.temp + "°F");
      $("#weather-title").text(data.query.results.channel.title);
      $("#weather-text").text(data.query.results.channel.item.condition.text);
      $("#weather-speed").text("Wind: " + data.query.results.channel.wind.speed + " mph");
      $("#weather-sunset").text("Sunset: " + data.query.results.channel.astronomy.sunset);
      var iconUrl = 'https://s.yimg.com/zz/combo?a/i/us/we/52/'
      var weatherCode = data.query.results.channel.item.condition.code;
      $(".weather_icon").attr('src', iconUrl + weatherCode + '.gif');
  });
});

Solution

  • For getJSON the success callback can be passed in as the second argument.

    Ref. http://api.jquery.com/jQuery.getJSON/

    $.getJSON("https://query.yahooapis.com/v1/public/yql?q=" + searchtext + "&format=json", function(data){
          $('#weather-temp').html(data.query.results.channel.item.condition.temp + "°F");
          $("#weather-title").text(data.query.results.channel.title);
          $("#weather-text").text(data.query.results.channel.item.condition.text);
          $("#weather-speed").text("Wind: " + data.query.results.channel.wind.speed + " mph");
          $("#weather-sunset").text("Sunset: " + data.query.results.channel.astronomy.sunset);
          var iconUrl = 'https://s.yimg.com/zz/combo?a/i/us/we/52/'
          var weatherCode = data.query.results.channel.item.condition.code;
          $(".weather_icon").attr('src', iconUrl + weatherCode + '.gif');
      });