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

    搬运:http://www.ynmm5.cc/index.php/2018/12/05/%E5%B0%86xmlrequest-%E6%94%B9%E5%86%99%E6%88%90fetch/

  • 相关阅读:
    安装IIS
    SQL 通过某个字段名称找到数据库中对应的表
    javascript 操作 drop down list
    The project type is not supported by this installationVS2005
    Get 和 Post 简介
    .Net 控件调用 javascript事件
    JQuery检测浏览器版本
    开车要点
    linux shell工程师要求
    memory management
  • 原文地址:https://www.cnblogs.com/kazama/p/10197587.html
Copyright © 2011-2022 走看看