not well-formed Source File in mozilla firefox

笑着哭i 提交于 2020-01-05 09:06:33

问题


Following is the content of my JSON File -

{
    "tags": [
        "Red",
        "Green",
        "Blue",
        "Yellow"
    ]
}

I checked this with jsonlint but still I am getting the following error in firefox.

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.

FYI -

OS - Linux Ubuntu 12.04

Firefox - 24.0

EDIT

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.

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.


回答1:


After few hours of searching I came across that -

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.

Source -

  1. Cross Origin Script Stackoverflow Answer
  2. Simple Solution For Local Cross Origin Requests


来源:https://stackoverflow.com/questions/24277695/not-well-formed-source-file-in-mozilla-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!