fetch post请求使用方法

 function getkey(obj) {
            var arr = []
            var str = ''
            for (const key in obj) {
                arr.push(key + "=" + obj[key])
            }
            str = arr.join('&')
        }
        var aaa = {
            name: '技术监督局',
            age: 12981
        }
        var req = new Request('http://localhost/tclproject/php/conent.php', {
            method: "POST",
            // credentials: 'include',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
            mode: "cors",
            body: getkey(aaa)
        })
        fetch(req)
            .then(
                (res) => {
                     res.json();
                }
            )
            .then(
                (data) => {
                    console.log(data);
                }
            )

你可能感兴趣的:(fetch post请求使用方法)