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);
    }
    }

    摘自:https://www.cnblogs.com/orange123/p/10179611.html

  • 相关阅读:
    查看ASM 使用率
    修改一行和修改全表的TX锁
    OCP-1Z0-053-V12.02-683题
    专栏成书亦可行也!——leo鉴书48
    Java用正则表达式判断是否为IP
    OCP-1Z0-053-V12.02-594题
    OCP-1Z0-053-V12.02-585题
    OCP-1Z0-053-V12.02-569题
    OCP-1Z0-053-V12.02-568题
    OCP-1Z0-053-V13.02-517题
  • 原文地址:https://www.cnblogs.com/smartchan/p/10189428.html
Copyright © 2011-2022 走看看