码迷,mamicode.com
首页 > Web开发 > 详细

ajax

时间:2018-11-15 22:39:25      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:作用   com   app   lan   取数   utf-8   fun   html   style   

<!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

标签:作用   com   app   lan   取数   utf-8   fun   html   style   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!