sca*_*t17 6 javascript xmlhttprequest fetch-api
我开始构建一个 Reactjs 应用程序,它使用 Fetch API 来处理我对 Web API 的请求。在为 Azure 应用程序设置 Microsoft 身份验证之前,我没有遇到任何问题,现在我的请求引发了 CORS 错误。
为了解决可能出现的问题,我使用 XHR 设置了相同的请求。我能够毫无问题地完成请求。我想知道是否有人能够告诉我我哪里出错了?
XHR版
var oReq = new XMLHttpRequest();  
oReq.open('get', 'https://myazureapp.azurewebsites.net/api/user', true);  
oReq.send();
获取 API 版本
fetch('https://myazureapp.azurewebsites.net/api/user');
这是我的错误:
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'https://myazureapp.azurewebsites.net' is therefore
not allowed access. If an opaque response serves your needs, set the
request's mode to 'no-cors' to fetch the resource with CORS disabled.
任何关于我可能做错了什么的见解都会很棒。如果您需要更多信息,请告诉我,我会相应地更新我的问题。