我试图加载一个3D模型,存储在我的电脑本地,到Three.js与JSONLoader, 3D模型是在同一目录下,作为整个网站。

我得到了“跨起源请求只支持HTTP.”错误,但我不知道是什么原因导致它也不知道如何修复它。


当前回答

Url应该像这样:

 createUserURL = "http://www.localhost:3000/api/angular/users"

而不是:

 createUserURL = "localhost:3000/api/angular/users"

其他回答

我将列出3种不同的方法来解决这个问题:

Using a very lightweight npm package: Install live-server using npm install -g live-server. Then, go to that directory open the terminal and type live-server and hit enter, page will be served at localhost:8080. BONUS: It also supports hot reloading by default. Using a lightweight Google Chrome app developed by Google: Install the app, then go to the apps tab in Chrome and open the app. In the app point it to the right folder. Your page will be served! Modifying Chrome shortcut in windows: Create a Chrome browser's shortcut. Right-click on the icon and open properties. In properties, edit target to "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:/ChromeDevSession" and save. Then using Chrome open the page using ctrl+o. NOTE: Do NOT use this shortcut for regular browsing.

注意:使用类似http://localhost:8080的http://以防出错。

今天碰到了这个。

我写了一些像这样的代码:

app.controller('ctrlr', function($scope, $http){
    $http.get('localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

...但它应该是这样的:

app.controller('ctrlr', function($scope, $http){
    $http.get('http://localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

唯一的区别是第二段代码中没有http://。

只是想把它放出来,以防其他人有类似的问题。

当我下载一个页面进行离线查看时,我就遇到了这种情况。

我只需要从所有<link>和<script>标签中删除integrity="*****"和crossorigin="anonymous"属性

我也能够在使用以下href的锚标记时重新创建此错误消息:

<a href="javascript:">示例:一个标签</a> .

在我的情况下,一个标签被用来获得“指针光标”和事件实际上是由一些jQuery点击事件控制。我删除了href并添加了一个应用的类:

光标:指针;

简单的解决方案,谁使用VS Code

我得到这个错误已经有一段时间了。大多数答案都是可行的。但我找到了一个不同的解决方案。如果你不想处理node.js或任何其他解决方案在这里,你正在使用一个HTML文件(从另一个js文件调用函数或获取json api的)尝试使用Live Server扩展。

它允许您轻松地打开一个活动服务器。因为它创建了本地主机服务器,所以问题得到了解决。您可以通过打开HTML文件并右键单击编辑器并单击open with Live Server来启动localhost。

它基本上使用http://localhost/index.html加载文件,而不是使用file://....

EDIT

不需要有.html文件。您可以使用快捷方式启动活动服务器。

按(alt+L, alt+O)打开服务器,按(alt+L, alt+C)停止服务器。[在MAC上,cmd+L, cmd+O和cmd+L, cmd+C]

希望它能帮助到别人:)