在Mozilla Firefox合式没有源文件 [英] not well-formed Source File in mozilla firefox
问题描述
以下是我的 JSON
文件的内容 -
Following is the content of my JSON
File -
{
"tags": [
"Red",
"Green",
"Blue",
"Yellow"
]
}
我查了一下这与 jsonlint 但还是我收到以下错误在Firefox。
I checked this with jsonlint but still I am getting the following error in firefox.
时间戳:2014年日6月18日10:39:41 IST错误:没有很好地形成
源文件:
文件:///home/trial$c$c/trial$c$c/Projects/ang/18-06-2014/ang/content.json
线路:1,柱:1来源$ C $ C:{
Timestamp: Wednesday 18 June 2014 10:39:41 IST Error: not well-formed Source File: file:///home/trialcode/trialcode/Projects/ang/18-06-2014/ang/content.json Line: 1, Column: 1 Source Code: {
我不知道我在做什么错的,如果任何
I am not sure what I am doing wrong if any.
仅供参考 -
OS - Linux操作系统Ubuntu 12.04
OS - Linux Ubuntu 12.04
火狐 - 24.0
Firefox - 24.0
修改
我通过 $ http.get
方法使用 content.json
的角度控制文件的内容。
I am using the content of content.json
file in angular controller via $http.get
method.
我探索更多关于这种类型的错误,发现它与内容类型
设置有关。
I explored more about this kind of error and found it is related with the Content-Type
setting.
以下是完整code -
Following is the full code -
<!doctype html>
<html lang="en" ng-app="app">
<head>
<title>JSON Read In Angularjs</title>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script>
var app = angular.module('app', []);
app.controller('myCtrl', function($scope, $http){
$scope.data = {};
$http.get('content.json').success(function(data) {
$scope.data = data;
});
});
</script>
</head>
<body ng-controller="myCtrl">
<ul>
<li ng-repeat="em in data.tags">{{em}}</li>
</ul>
</body>
</html>
我设置的内容类型,如果这是一个问题怎么办。我搜索这里但无法修复它。帮我请(如有)。
How do I set the content type if that is a problem. I searched HERE but unable to fix it. Help me Please if any.
推荐答案
搜索我的几个小时后跨过来了 -
After few hours of searching I came across that -
浏览器和其他现代浏览器已经实现安全
限制跨原产地采购,这意味着你不能
通过文件加载任何东西:///,您需要使用http://协议在
任何时候,甚至在当地-due同源政策。
Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies.
源代码 -
- Cross Origin Script Stackoverflow Answer
- Simple Solution For Local Cross Origin Requests
这篇关于在Mozilla Firefox合式没有源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!