zoukankan      html  css  js  c++  java
  • async/wait使用fetch 与generator使用fetch

    1.

    // Example POST method implementation:
    async function postData(url='15479453.html', data={}) {
        // Default options are marked with *
        const response = await fetch(url, {
            method: 'POST',
            // *GET, POST, PUT, DELETE, etc.
            mode: 'cors',
            // no-cors, *cors, same-origin
            cache: 'no-cache',
            // *default, no-cache, reload, force-cache, only-if-cached
            credentials: 'same-origin',
            // include, *same-origin, omit
            headers: {
                'Content-Type': 'application/json'// 'Content-Type': 'application/x-www-form-urlencoded',
            },
            redirect: 'follow',
            // manual, *follow, error
            referrerPolicy: 'no-referrer',
            // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
            body: JSON.stringify(data)// body data type must match "Content-Type" header
        });
        return response.text();
        // parses JSON response into native JavaScript objects
    }
    
    postData('15479453.html', {
        answer: 42
    }).then(data=>{
        console.log(data);
        // JSON data parsed by `data.json()` call
    }
    );

    2.

    function *gen() {
        // var url = 'https://api.github.com/users/github';
        var url = 'https//:www.baidu.com';
        var result = (yield fetch("15479453.html"));
        console.log("result
    ", result.slice(0, 20));
        return result;
    }
    var g = gen();
    var result = g.next();
    console.log("g.next()")
    
    result.value.then(function(data) {
        return data.text();
    }).then(function(data) {
        console.log("g.next(data)
    ", g.next(data));
    });
  • 相关阅读:
    mysql升级大致
    初始化配置文件的使用:/etc/my.cnf
    mysql用户管理
    MySql的逻辑结构(抽象结构)与物理结构
    5.7与5.6版本在部署方面的改变
    MySql服务器进程结构
    MySql服务器构成 --实列
    mysql客户端与服务器端模型
    RDBMS和NoSQL区别即主流sql
    MySql基本操作
  • 原文地址:https://www.cnblogs.com/sunupo/p/15538986.html
Copyright © 2011-2022 走看看