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> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】博客园2025新款「AI繁忙」系列T恤上架,前往周边小店选购
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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详细过程