1

我正在尝试测试 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(variable)”用 jquery 覆盖元素中的 html 时,刷新实际页面时没有任何注册。任何帮助将不胜感激。

4

1 回答 1

2

它应该是:

$.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);})

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

于 2017-05-16T21:29:35.003 回答