七度&光 2017-04-03 12:56 采纳率: 22.2%
浏览 82

为什么AJAX调用不起作用?

我正在尝试从openweathermap网站获取JSON数据,下面是我编写的jQuery代码,我的目标是在控制台中记录JSON数据,但控制台日志什么也没显示。我尝试了警报功能是否正常工作,但是没有显示警报对话框。我无法确定问题出在哪里,请帮帮我吧!

$(document).ready(function(){

    $("#submitButton").click(function(){

        //alert("Hello");
        return getWeather();

    });
});

function getWeather(){


    var city=$("#city").val();

    if(city != ''){

        $.ajax({


            url : 'http://api.openweathermap.org/data/2.5/weather?q=' + city + "&units=metric" + "&APPID=8eca04841762dd31f99510429e97970a",
            type:"GET",
            dataType:"jsonp",
            success:function(data){

                //alert("hello");
                console.log(data);
                $("#showWeather").html();
            }

        });

    }

    else{


        $("#error").html("<div>City field cannot be empty</div>");
    }
}
  • 写回答

2条回答 默认 最新

  • weixin_33705053 2017-04-03 13:44
    关注

    Your API link using http protocol (not https). So it is possible reason why Mixed content error happened.

    That's why you can see nothing or notice in some browsers that some insecure content is hidden.

    So possible solution is to use http on your site to avoid mixed content. But it is strongly recommended to use https on both servers.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?