AJAX jSON资源 ,jsonplaceholder.typicode

 http://jsonplaceholder.typicode.com/ 是一个可以做AJAX练习的网站。

JQuery 和ES6 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="zh-cmn-Hans" class="ua-windows ua-webkit">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="always">
      <script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
    <title>json</title>
    <style></style>
</head>
<body>
    <div class="people">
    </div>
    <button id="clash">Clash!</button>
 <script>
window.onload= function(){
    const clash = document.querySelector('#clash');
    clash.onclick = getData;
        function getData(){
        $.get('http://jsonplaceholder.typicode.com/posts',setDom)
             let people = document.querySelector('.people');
                let hasName = people.className.includes('got')?true:false;
                console.log(hasName);
                function setDom(data){
                if(!hasName){
                 for(let i=0;i<data.length;i++){
                      people.innerHTML +=`${data[i].id} ${data[i].title} `;
                    }
                    people.className +=' got';
                    }else{
                     people.className = 'people';
                        people.innerHTML ='';
                    }
                }
     }
    
}
    </script>
</body>
</html>

  

posted @   Esther_Cheung  阅读(3018)  评论(0)    收藏  举报
编辑推荐:
· Linux系列:如何用perf跟踪.NET程序的mmap泄露
· 日常问题排查-空闲一段时间再请求就超时
· Java虚拟机代码是如何一步一步变复杂且难以理解的?
· 领域驱动的事实与谬误 一 DDD 与 MVC
· SQL Server 2025 中的改进
阅读排行:
· C#/.NET/.NET Core优秀项目和框架2025年4月简报
· Linux系列:如何用perf跟踪.NET程序的mmap泄露
· 为什么AI多轮对话那么傻?
· .NET + AI | Semantic Kernel vs Microsoft.Extension
· windows11 安装WSL2详细过程
点击右上角即可分享
微信分享提示