首页 > Web开发 > 详细

ajax

时间:2018-11-15 21:54:58      阅读:174      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax</title>
</head>
<body>
<ul>

</ul>
<script src="js/jQuery3.3.1.js"></script>
<script>
    $(function () {
        $.ajax(   //ajax 是jquery封装好的一个事件
            {url: "https://free-api.heweather.com/s6/weather/now?location=changping,北京&key=83a29964479c488d8b42d884bbf0fcb0",  //访问服务器获取数据
             type: "get", // 访问方式
             success:function (data) { //请求成功作用域
                 let arr = data.HeWeather6[0].now;
                 console.dir(arr);
                 Object.keys(arr).forEach(function (item) {   //遍历对象 }{字典}
                     $(`<li>${item }: ${arr[item]}</li>`).appendTo("ul")   //使用forEach
                     })
             },
                 error: function (data) { //请求失败作用域
                     console.log(data)
                 }
            }
            )
    })
</script>
</body>
</html>

 

ajax

原文:https://www.cnblogs.com/tcpblog/p/9966192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!