“仅 HTTP 支持跨源请求."加载本地文件时出错 [英] "Cross origin requests are only supported for HTTP." error when loading a local file

查看:30
本文介绍了“仅 HTTP 支持跨源请求."加载本地文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JSONLoader 将 3D 模型加载到 Three.js 中,并且该 3D 模型与整个网站位于同一目录中.

I'm trying to load a 3D model into Three.js with JSONLoader, and that 3D model is in the same directory as the entire website.

我收到 Cross origin requests are only supported for HTTP." 错误,但我不知道是什么原因造成的,也不知道如何解决.

I'm getting the "Cross origin requests are only supported for HTTP." error, but I don't know what's causing it nor how to fix it.

推荐答案

我的水晶球说你正在使用 file://C:/ 加载模型>,它对错误消息保持真实,因为它们不是 http://

My crystal ball says that you are loading the model using either file:// or C:/, which stays true to the error message as they are not http://

因此,您可以在本地 PC 上安装网络服务器或将模型上传到其他地方并使用 jsonp 并将 url 更改为 http://example.com/path/to/模型

So you can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to http://example.com/path/to/model

Origin 在 RFC-6454 中定义为

Origin is defined in RFC-6454 as

   ...they have the same
   scheme, host, and port.  (See Section 4 for full details.)

所以即使你的文件来自同一个主机(localhost),但只要方案不同(http/file),它们被视为不同的来源.

So even though your file originates from the same host (localhost), but as long as the scheme is different (http / file), they are treated as different origin.

这篇关于“仅 HTTP 支持跨源请求."加载本地文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆