且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

请求的资源错误中不存在“Access-Control-Allow-Origin"标头

更新时间:2022-02-12 03:34:08

我相信这可能是 Chrome 不支持 localhost 去通过 Access-Control-Allow-Origin -- 查看 Chrome 问题

I believe this might likely be that Chrome does not support localhost to go through the Access-Control-Allow-Origin -- see Chrome issue

要让 Chrome 在标头中发送 Access-Control-Allow-Origin,只需将/etc/hosts 文件中的本地主机别名为其他域,例如:

To have Chrome send Access-Control-Allow-Origin in the header, just alias your localhost in your /etc/hosts file to some other domain, like:

127.0.0.1   localhost yourdomain.com

然后,如果您使用 yourdomain.com 而不是 localhost 访问您的脚本,调用应该会成功.

Then if you'd access your script using yourdomain.com instead of localhost, the call should succeed.