[英]AngularJS error Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource
I'am traying to navigate between to pages with angularJS but when i open the main page with my browser it doesn't display anything when i look in the console i see this error : 我正在托盘中导航到带有angularJS的页面,但是当我用浏览器打开主页时,当我在控制台中查看时它什么也没显示:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
here is my code: 这是我的代码:
ViewsTestPage: ViewsTestPage:
<html>
<head>
<title>Views Test</title>
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="controller.js"></script>
</head>
<body ng-app="myApp">
<div ng-view></div>
</body>
</html>
the controller.js: controller.js:
var mainApp = angular.module('myApp', ['ngRoute']);
mainApp.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'UsersPage.html'
})
.when('/helloUser', {
templateUrl: 'hello.html'
})
.otherwise({
redirectTo: '/'
});
});
UsersPage : 用户页面:
Hello world <a href="#/helloUser">Hi users</a>
hello.html hello.html
<h1> Users Page</h1>
any help please i'am begginner!!!! 任何帮助,请我开始!!
From this answer from a similar question which has already been shared 从这个已经被分享的类似问题的 答案中
npm install http-server -g
and then start http-server C:\\location\\to\\app
. npm install http-server -g
,然后启动http-server C:\\location\\to\\app
。 10.122.32.213:6060
(have put a random address) 10.122.32.213:6060
: 10.122.32.213:6060
(放置了一个随机地址) templateUrl: 'http://10.122.32.213:6060/UsersPage.html'
templateUrl: 'http://10.122.32.213:6060/UsersPage.html'
Hope this helps! 希望这可以帮助!
This error is happening because you are just opening html documents directly from the browser. 发生此错误是因为您只是直接从浏览器中打开html文档。 To fix this you will need to serve your code from a webserver and access it on localhost.
要解决此问题,您将需要从Web服务器提供代码并在localhost上访问它。 If you have Apache setup, use it to serve your files.
如果您有Apache设置,请使用它来提供文件。 Some IDE's have built in web servers, like JetBrains IDE's, Eclipse.. If you have webstorm then you can open it from webstorm.
一些IDE内置了Web服务器,例如JetBrains IDE的Eclipse。。如果您有webstorm,则可以从webstorm中打开它。
If you have Node.Js setup then you can use http-server. 如果已安装Node.Js,则可以使用http服务器。 Just run npm install
http-server -g
and you will be able to use it in terminal like http-server C:\\location\\to\\app.
只需运行npm install
http-server -g
,您就可以在终端上使用它,例如http-server C:\\location\\to\\app.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.