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

AJAX jSON资源 ,jsonplaceholder.typicode

时间:2017-12-04 14:11:29      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:else   includes   windows   rip   lan   html   set   es6   utf-8   

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

JQuery 和ES6 :

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

  

AJAX jSON资源 ,jsonplaceholder.typicode

标签:else   includes   windows   rip   lan   html   set   es6   utf-8   

原文地址:http://www.cnblogs.com/xinfangzhang/p/7976628.html

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