zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    Fetch & POST

    
        fetch(
            `http://10.1.5.202/deploy/http/send/viewtree`,
            {
                method: "POST",
                mode: "cors",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",// type
                },
                body: JSON.stringify({"pro_name":"SYDBS.trunk"}),// form url string
            }
        )
        .then(res => res.json())
        .then(
            (json) => {
                console.log(`post json`, json);
                return json;
            }
        )
        .catch(err => console.log(`fetch post error`, err));
    
    

    image

    POST & form query url

    
    const fetchPOSTJSON = (url = ``, queryObj = {}) => {
        let {
            pro_name,
            apis,
            message
        } = queryObj;
        let query = `pro_name=${pro_name}&apis=${JSON.stringify(apis)}&message=${message}`;
        return fetch(url,
            {
                method: "POST",
                mode: "cors",
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                    // "Content-Type": "application/json",
                    // "Content-Type": "application/json; charset=utf-8",
                },
                // body: JSON.stringify(queryObj),// object
                // body: queryObj,// object
                body: query,// string
            })
            .then(res => res.json())
            .then(
                (json) => {
                    console.log(`post json`, json);
                    return json;
                }
            ).catch(err => console.log(`fetch post error`, err));
    };
    
    

  • 相关阅读:
    HTML入门之003
    html入门之002
    HTML入门之001
    端口
    计算机基础
    二进制的学习
    markdown基础
    css基础
    html基础之三
    html基础之二
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/9252386.html
Copyright © 2011-2022 走看看