直接上代码:
fetch('/api', {
method: "GET",
// body: JSON.stringify({timestamp: 'hello world.'}),
/* headers: {
"Content-Type": "application/json"
},*/
// credentials: "same-origin" //需要使用cookies
}).then(function(response) {
return response.text();
}).then(function (res) {
console.log(res);
}).catch(function (error) {
console.log(error);
});