跨起源请求仅支持HTTP [英] Cross origin requests are only supported for HTTP
本文介绍了跨起源请求仅支持HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这跑code:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Exemple 06</title>
</head>
<body>
<!-- Diretiva ng-repeat -->
<div ng-controller="MyController">
<a ng-href="#/">Page 1</a> | <a ng-href="#/p2">Page 2</a>
<div ng-view="#/p2"></div>
</div>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider
.when('/' , {controller: 'MyController', templateUrl: 'p1.html'})
.when('/p2', {controller: 'MyController', templateUrl: 'p2.html'})
.otherwise({ redirectTo: '/'});
});
myApp.controller('MyController', function($scope){
$scope.nomes = [
{id: 1, nome: 'Arthur'},
{id: 2, nome: 'Portos'},
{id: 3, nome: 'Aramis'}
];
});
</script>
</body>
但低于发生错误:
XMLHtt prequest无法加载文件:///home/93579551515/Desktop/Angular/p1.html。跨起源请求仅支持HTTP。
XMLHttpRequest cannot load file:///home/93579551515/Desktop/Angular/p1.html. Cross origin requests are only supported for HTTP.
我不想在Web服务器上运行。
I don't want to run it on a webserver.
推荐答案
您可以添加模板,如 p1.html
和 p2.html
在 index.html的
通过将它们脚本中
标签,为的mentioned在文档。
You can add templates such as p1.html
and p2.html
in your index.html
by putting them inside script
tags, as mentioned in the docs.
<script type="text/ng-template" id="p1.html">
This is the content of the template
</script>
然后角
将不再需要进行AJAX请求获取它们。
Then angular
will no longer need to make AJAX requests to fetch them.
请注意,这些剧本
元素必须出现的之后的 NG-应用
。
Do note that these script
elements must appear after ng-app
.
这篇关于跨起源请求仅支持HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文