0

Following the tutorial provided here for routing in AngularJS, I am trying to run the same in my local.

I have the index.html as

index.html

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>

<body ng-app="myApp">

<p><a href="#/">Main</a></p>

<a href="#red">Red</a>
<a href="#green">Green</a>
<a href="#blue">Blue</a>

<div ng-view></div>

<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "main.htm"
    })
    .when("/red", {
        templateUrl : "red.htm"
    })
    .when("/green", {
        templateUrl : "green.htm"
    })
    .when("/blue", {
        templateUrl : "blue.htm"
    });
});
</script>
</body>
</html>

main.htm

<html>
<head></head>
<body>
This is main
</body>
</html>

red.htm

<html>
<head></head>
<body>
This is red
</body>
</html>

And so for green.htm and blue.htm

When I run in Firefox, it works as expected - output below

enter image description here

But the same when I open in Chrome, the result is

enter image description here

What I need to do for resolving this CORS issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173

1 Answers1

0

It works without any issues on chrome for me. Here is the link to the working Plunker: http://plnkr.co/edit/dyaY1CBvay8VXIZ2blTx?p=preview

// Code goes here

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "main.html"
    })
     .when("/green", {
        templateUrl : "green.html"
    })
    .when("/blue", {
    templateUrl : "blue.html"
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>

  <head>
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="myApp">
    <p><a href="#/">Main</a></p>
    <a href="#green">Green</a>
    <a href="#blue">Blue</a>
    <div ng-view></div>
  </body>

</html>
user6801750
  • 242
  • 3
  • 12
  • even the article link I posted works too in chrome. But when I did the same in my local, it's working fine in FF but not in Chrome – priyanka.sarkar Sep 07 '16 at 03:52
  • Please post the exact code from your local as it will help to debug it. – user6801750 Sep 07 '16 at 04:02
  • What IDE are you using? I tried your code on Windows 8.1 using Visual Studio 2013 and it is working fine on Chrome. There is another similar post:http://stackoverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht – user6801750 Sep 07 '16 at 11:51