0

I am unsure why, but it seems that when I call $.getJSON after another getJson has been called, nothing happens. Here is the code:

getWeather();

function getWeather() {
    $.getJSON("http://where.yahooapis.com/geocode?q=" + lat + ",+" + lon + "&gflags=R&flags=J", function(data){
        zipCode = data.ResultSet.Results[0].postal;
        WOEID = data.ResultSet.Results[0].woeid;
        getYahooWeather(WOEID);         
    });
}

function getYahooWeather(x) {
    var query = escape('select item from weather.forecast where woeid="'+x+'"');
    var url = "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=c";
    console.log(url);

    $.getJSON(url, function(data2){
        console.log("hey");
    });
}

My question is, am I doing something wrong with these $.getJSON calls?

Thanks so much

Vinny
  • 309
  • 3
  • 11
  • check your console for cross-domain-policy error – Yaron U. Apr 29 '12 at 22:55
  • Is this question a possible duplicate of http://stackoverflow.com/questions/5492838/why-does-getjson-silently-fail? – jkwuc89 Apr 29 '12 at 22:56
  • the console doesn't say anything. it should say hey. the first getJSON works fine. the second one doesn't work – Vinny Apr 29 '12 at 23:00
  • do those functions ever get called at all? do a `console.log()` for each, both before and after their `getJSON()`. check where the chain of execution cuts off. – Joseph Apr 29 '12 at 23:01
  • in the first function, the console will show zipCode and WOEID. in the second function it will show the url. but it does not show hey – Vinny Apr 29 '12 at 23:05

2 Answers2

3

You have specified that the callback should be the c function, so declare it:

function getYahooWeather(x) {
  var query = escape('select item from weather.forecast where woeid="'+x+'"');
  var url = "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=c";
  console.log(url);

  $.getJSON(url);
}

function c(data2) {
  console.log("hey");
}
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • gahhhhhhhhhhhhh, that's what copying and pasting will do to you!! thanks so much for telling me that! – Vinny Apr 29 '12 at 23:09
1

Your request is outside the current domain. You cannot make foreign request, it is restricted by cross-domain policy.

Such requests and made using a jsonp request instead. And here is a guide to get you started.

Starx
  • 77,474
  • 47
  • 185
  • 261