Vinny
Vinny

Reputation: 309

$.getJSON not doing anything

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

Upvotes: 0

Views: 280

Answers (2)

Guffa
Guffa

Reputation: 700222

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

Upvotes: 3

Starx
Starx

Reputation: 78971

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.

Upvotes: 1

Related Questions