有關Fetch與axios與跨域請求
有關Fetch
fetch('http://localhost:3001/getArticle',{
method: 'GET',
})
.then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText)
error.response = response;
throw error;
}
})
.then((data) => {
console.log(data)
})
.catch(function(error) {
console.log('request failed', error);
return error.response.json();
})如果要傳JSON要先stringify
Fetch 取得 server 錯誤訊息
Axios
注意:
#瀏覽器跨域請求
下載檔案
Last updated