Jquery 拉取简单天气变量(JSON/API)

Jquery 拉取简单天气变量(JSON/API),jquery,html,json,api,Jquery,Html,Json,Api,我想从以下API URL中提取一个简单的“当前天气”状态,以集成到网站中: 我正在寻找一个问题的两种解决方案之一。或者了解一下为什么这段代码不会返回简单的“Testing”(如果我删除“$.getJSON”行,它会返回)。或者我需要包含的完整jQuery,用于当前条件>临时条件 <script> $(document).ready(function(){ $.getJSON( 'http://free.worldweatheron

我想从以下API URL中提取一个简单的“当前天气”状态,以集成到网站中:

我正在寻找一个问题的两种解决方案之一。或者了解一下为什么这段代码不会返回简单的“Testing”(如果我删除“$.getJSON”行,它会返回)。或者我需要包含的完整jQuery,用于当前条件>临时条件

<script>
    $(document).ready(function(){
      $.getJSON(
                'http://free.worldweatheronline.com/feed/weather.ashx?q=67554&format=json&num_of_days=2&key=794496e1c2020558131802',
                function(data) {
                  var output="Testing.";
                  document.getElementById("weather").innerHTML=output;   
                });
    });
</script>

$(文档).ready(函数(){
$.getJSON(
'http://free.worldweatheronline.com/feed/weather.ashx?q=67554&format=json&num_of_days=2&key=794496e1c2020558131802',
功能(数据){
var output=“测试。”;
document.getElementById(“天气”).innerHTML=输出;
});
});
提前感谢您的帮助;我真的很感激

这是因为。您应该使用
jsonp
&将代码更改为:

$(document).ready(function () {
    $.ajax({
        url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=67554&format=json&num_of_days=2&key=794496e1c2020558131802',
        type: "GET",
        dataType: "jsonp",
        success: function (data) {
            console.log(data); //to see that data is indeed returned
            var output = "Testing.";
            $("#weather").html(output);
        }
    });
});
这是因为。您应该使用
jsonp
&将代码更改为:

$(document).ready(function () {
    $.ajax({
        url: 'http://free.worldweatheronline.com/feed/weather.ashx?q=67554&format=json&num_of_days=2&key=794496e1c2020558131802',
        type: "GET",
        dataType: "jsonp",
        success: function (data) {
            console.log(data); //to see that data is indeed returned
            var output = "Testing.";
            $("#weather").html(output);
        }
    });
});

是的,我刚打了同样的东西,但你先回答了。这是我放进去的。太好了,非常感谢!!我唯一的编辑(以防将来有人引用这个问题)是,我们需要在“weather”前面加一个“#”,因为它标识一个ID。除此之外,还有惊人之处。=)再次感谢!!是的,我刚打了同样的东西,但你先回答了。这是我放进去的。太好了,非常感谢!!我唯一的编辑(以防将来有人引用这个问题)是,我们需要在“weather”前面加一个“#”,因为它标识一个ID。除此之外,还有惊人之处。=)再次感谢!!