2012-04-29 40 views
0

我不确定为什么,但似乎在调用另一个getJson之后调用$ .getJSON时,没有任何反应。这里是代码:

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

我的问题是,我做错了这些$ .getJSON调用?

非常感谢

+0

什么控制台说? – Joseph

+0

检查您的控制台的跨域策略错误 –

+0

这个问题可能是http://stackoverflow.com/questions/5492838/why-does-getjson-silently-fail的重复? – jkwuc89

回答

3

你指定的回调应该是c功能,所以其声明:

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

gahhhhhhhhhhhhh,这就是复制和粘贴会对你做什么!非常感谢你告诉我! – Vinny

1

您的请求位于当前域名之外。您不能作出国外请求,它受到跨域策略的限制。

这样的请求并使用jsonp请求代替。这里有一个guide让你开始。