xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Fetch & POST

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


posted @ 2018-07-02 09:34  xgqfrms  阅读(131)  评论(5编辑  收藏  举报