关键词 mode cors
accept : json
const url = "http://localhost:8080/api/values/1";
fetch(url, {
method: "GET",
mode: "cors",
headers: {
//"Content-Type": "application/json; charset=utf-8"
'Accept': 'application/json'
}
}).then(response => response.json())
.then(result => {
// 在此处写获取数据之后的处理逻辑
console.log(result);
}).catch(function (e) {
//console.log("fetch fail", JSON.stringify(params));
});
iis的服务器 http 响应头添加 Access-Control-Allow-Headers:Content-Type, api_key, Authorization
以及 Access-Control-Allow-Origin:*
服务器返回的json 可以直接通过response.json() 获取