0

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');
  });
});
Dan Nick
  • 514
  • 1
  • 9
  • 30
  • `success` is an ajax option on the properties of the request, not a function on the deferred. – Taplar Mar 15 '19 at 16:01

2 Answers2

2

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');
  });
Taplar
  • 24,788
  • 4
  • 22
  • 35
0

Look here: http://api.jquery.com/jQuery.ajax/

.done(function() {
  //do stuff
});
Onix
  • 2,129
  • 2
  • 17
  • 26