繁体   English   中英

$ .getJSON什么都不做

[英]$.getJSON not doing anything

我不确定为什么,但是似乎当我在另一个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调用是否做错了?

非常感谢

您已指定回调应为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");
}

您的请求不在当前域内。 无法发出外部请求,它受到跨域策略的限制。

此类请求使用jsonp请求代替。 这是指导您入门的指南

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM