no access-control allow-origin header 错误,但调用不是跨站的

no access-control allow-origin header error, but the call is not cross-site

我不明白以下错误,因为我没有做任何离开域的事情。调用是从example.comexample.com。或者 www 前缀是否被视为与裸域分开的域?

XMLHttpRequest cannot load https://www.example.com/foo/SearchHandler.ashx.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://example.com' is therefore not allowed access.

来源定义为协议、完整主机名和端口: https://en.wikipedia.org/wiki/Same-origin_policy

所以是的,example.com 和 www.example.com 被视为两个不同的来源,因此您需要 Access-Control-Allow-Origin.