简体   繁体   English

$ .getJSON什么都不做

[英]$.getJSON not doing anything

I am unsure why, but it seems that when I call $.getJSON after another getJson has been called, nothing happens. 我不确定为什么,但是似乎当我在另一个getJson被调用之后调用$ .getJSON时,什么也没发生。 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? 我的问题是,这些$ .getJSON调用是否做错了?

Thanks so much 非常感谢

You have specified that the callback should be the c function, so declare it: 您已指定回调应为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");
}

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. 此类请求使用jsonp请求代替。 And here is a guide to get you started. 这是指导您入门的指南

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

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