对于 JavaScript 的 Fetch API,"same-origin" 和 "no-cors" 之间有什么区别?

What's the difference between "same-origin" and "no-cors" for JavaScript's Fetch API?

我认为同源意味着没有 CORS,反之亦然。 JavaScript 的 Fetch API 的 mode 选项的两个选项有什么区别?

此外,在规格中,它说:

Even though the default request mode is "no-cors", standards are highly discouraged from using it for new features. It is rather unsafe.

为什么不安全?资料来源:https://fetch.spec.whatwg.org/#requests

使用 same-origin 您只能对您的来源执行请求,否则请求将导致错误。

使用 no-cors,您可以向其他源执行请求,即使它们没有设置所需的 CORS headers,但您会得到一个 opaque response

您可以在 MDN 上阅读更多内容:https://developer.mozilla.org/en-US/docs/Web/API/Request/mode and https://developer.mozilla.org/en-US/docs/Web/API/Response/type