Angular JS:无法在 'XMLHttpRequest' 上执行 'send'
Angular JS : Failed to execute 'send' on 'XMLHttpRequest'
我正在尝试通过 Angular 名为 $http.But 的内置服务读取 json 文件,该页面给我一个错误 "Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load respective json file"。
这是我的代码:
angularExample.html
<!DOCTYPE html>
<html ng-app="Fino">
<head>
<link rel="stylesheet" type="text/css" href="scripts/bootstrap.min.css" />
<script type="text/javascript" src="scripts/angular.min.js"></script>
<script type="text/javascript" src="scripts/app.js"></script>
</head>
<body ng-controller="FinController as fin">
<ul ng-repeat="emp in fin.employees" >
<li>Name:{{emp.name}}</li>
<li>Age:{{emp.age}}</li>
</ul>
</body>
</html>
app.js
var app=angular.module("Fino",[]);
app.controller('FinController',['$http',function($http){
var store=this;
$http.get('emp.json').success(function(data){
store.employees=data;
});
}]);
emp.json
[
{name:'abc',age:27},
{name:'bcd',age:24},
{name:'efg',age:22}
];
错误快照:
正如@Puneetsri 所说,最好的选择是将您的文件托管在网络服务器上。否则尝试在使用以下标志
启动应用后在 chrome 中启动它
chrome.exe --allow-file-access-from-files
我正在尝试通过 Angular 名为 $http.But 的内置服务读取 json 文件,该页面给我一个错误 "Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load respective json file"。
这是我的代码:
angularExample.html
<!DOCTYPE html>
<html ng-app="Fino">
<head>
<link rel="stylesheet" type="text/css" href="scripts/bootstrap.min.css" />
<script type="text/javascript" src="scripts/angular.min.js"></script>
<script type="text/javascript" src="scripts/app.js"></script>
</head>
<body ng-controller="FinController as fin">
<ul ng-repeat="emp in fin.employees" >
<li>Name:{{emp.name}}</li>
<li>Age:{{emp.age}}</li>
</ul>
</body>
</html>
app.js
var app=angular.module("Fino",[]);
app.controller('FinController',['$http',function($http){
var store=this;
$http.get('emp.json').success(function(data){
store.employees=data;
});
}]);
emp.json
[
{name:'abc',age:27},
{name:'bcd',age:24},
{name:'efg',age:22}
];
错误快照:
正如@Puneetsri 所说,最好的选择是将您的文件托管在网络服务器上。否则尝试在使用以下标志
启动应用后在 chrome 中启动它chrome.exe --allow-file-access-from-files