简体   繁体   English

AngularJS错误跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource

[英]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 从这个已经被分享的类似问题的 答案中

  1. Install Node.js 安装Node.js
  2. Run 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
  3. you will get the server address. 您将获得服务器地址。 For eg, 10.122.32.213:6060 (have put a random address) 例如, 10.122.32.213:606010.122.32.213:6060 (放置了一个随机地址)
  4. Use the above obtained address to link your file. 使用上面获得的地址链接您的文件。
  5. in your case 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.

相关问题 AngularJS错误:仅支持协议方案的跨源请求:http,数据,chrome扩展,https - AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https “仅协议方案支持跨源请求:http,数据,chrome,chrome扩展名,https,chrome-extension-resource。” - “Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.” json-server-跨源请求仅支持以下协议方案:http,data,chrome,chrome-extension - json-server - Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension “仅协议方案支持跨源请求”错误 - “Cross origin requests are only supported for protocol schemes” error 使用角度路由时出现错误仅协议方案仅支持跨源请求:http - Getting Error while using angular routing Cross origin requests are only supported for protocol schemes: http 在 Chrome-Extension 弹出窗口中使用 AngularJS 并显示范围内的数据 - Using AngularJS inside of the Chrome-Extension popup and display data from scope 加载程序未显示在chrome-extension - loader not showing up in chrome-extension chrome扩展中的angularjs模板 - angularjs templates in chrome extension angularjs和google chrome扩展 - angularjs and google chrome extension 在Chrome扩展程序中使用AngularJS - Use AngularJS in a Chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM