标签:跨域 必须 method aaa 处理 head let res token
function aaa(obj,src) { let postData = {a:‘b‘}; let ret = fetch(url, { method: ‘POST‘, headers: { ‘X-CSRF-TOKEN‘: "token", ‘Content-Type‘: ‘application/json‘ }, body: JSON.stringify(postData) })//必须两个then 才能得到正常的json .then(response=>response.json()) .then(data=>{ //这里才得到json }) }
/** * 使用async await */ async function delImg(obj,src) { let postData = {a:‘b‘}; let ret = await fetch(url, { method: ‘POST‘, headers: { ‘X-CSRF-TOKEN‘: "token", ‘Content-Type‘: ‘application/json‘ }, body: JSON.stringify(postData) }) //格式化返回的数据 let response =await ret.json(); if (response.status === ) { //在这里处理业务逻辑 } }
标签:跨域 必须 method aaa 处理 head let res token
原文地址:https://www.cnblogs.com/zqblog1314/p/12740296.html