zoukankan      html  css  js  c++  java
  • 将XMLrequest 改写成fetch

     

    var header = document.querySelector('header');
    var section = document.querySelector('section');

    fetch('https://raw.githubusercontent.com/gmhcy/ONEPIECE/master/onepiece.json')

    .then(function(response)

    { return response.json();

    })

    .then(function(myJson) {

    var onepiece = myJson;

    onepieceHeader(onepiece);
    showpeople(onepiece);

    });

     

    function onepieceHeader(jsonObj){
    var headline=document.createElement('h1');
    headline.textContent=jsonObj['tou'];
    header.appendChild(headline);
    var jies=document.createElement('p');
    jies.textContent=jsonObj['jieshao'];
    header.appendChild(jies);
    }
    function showpeople(jsonObj){
    var heroes=jsonObj['members'];
    for (var i = 0; i <heroes.length; i++) {
    var myArticle = document.createElement('article');
    var myH2 = document.createElement('h2');
    var myPara1 = document.createElement('p');
    var myPara2 = document.createElement('p');
    var myPara3 = document.createElement('p');
    var myPara4 = document.createElement('p');
    myH2.textContent = heroes[i].name;
    myPara1.textContent = 'age: ' + heroes[i].age;
    myPara2.textContent = 'power: ' + heroes[i].power;
    myPara3.textContent = 'hobby:'+heroes[i].hobby;
    myPara4.textContent = 'dream:'+heroes[i].dream;
    myArticle.appendChild(myH2);
    myArticle.appendChild(myPara1);
    myArticle.appendChild(myPara2);
    myArticle.appendChild(myPara3);
    myArticle.appendChild(myPara4);
    section.appendChild(myArticle);
    }
    }

     

  • 相关阅读:
    [Linux] expect命令 (自动交互脚本)
    [MAC] 终端bash_profile配置不生效问题
    [IDEA] 开发常用插件
    [MAC] 环境常用工具
    [IDEA] 快捷键输出固定代码模板
    家庭网络-多无线路由器实现无缝漫游
    家庭网络-AP组网方案(POE供电)
    家庭网络-软路由搭建方案
    队列使用
    [多线程] 线程池的使用
  • 原文地址:https://www.cnblogs.com/ggmh/p/10063943.html
Copyright © 2011-2022 走看看