console.log() 不会在 codepen.io 上将数据打印到控制台



我正在尝试测试 api 调用是否成功,但是当我调用函数中的 console.log(( 命令时,控制台中没有打印出任何内容。 请帮忙。

$.getJSON('http://freegeoip.net/json/').done(function(location){
        console.log(location.city);}

和。。。

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat='+latitude+'&lon='+longitude+'&unit=imperial&appid=5b98cbb01e7b431b5f074efdd59bb78b', function(data){
            apiData = data;
            console.log(apiData);}

此外,当我尝试用"$('#element'(.html(变量("覆盖 jquery 元素中的 html 时,当我刷新实际页面时没有任何记录。任何帮助将不胜感激。

它应该是:

$.getJSON('http://freegeoip.net/json/').done(function(location){
        console.log(location.city);})

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat='+latitude+'&lon='+longitude+'&unit=imperial&appid=5b98cbb01e7b431b5f074efdd59bb78b', function(data){
            apiData = data;
            console.log(apiData);})

这两种情况下都缺少结束括号(done(( 函数和回调函数(。

最新更新