var data = {"code":0,"msg":"你好"}; fetch("http://localhost:55087/Forguncy/ServerCommand/data", { method: 'POST', body: JSON.stringify(data) }) .then(response => response.json()) .then(response => { console.log(response) }) .catch(err => console.error(err)); //响应头有跨域头,就可以实现跨域 //GET访问 fetch('http://localhost:55087/Forguncy/ServerCommand/data') .then(response => { if (response.ok) { return response.text(); } throw new Error('Network response was not ok.'); }) .then(data => { console.log(data); }) .catch(error => { console.error('There was a problem with your fetch operation:', error); });