javascript - Cross-origin-requests in Angular.js -


i got angular.js app has run on client-only , needs fetch data different json files.

i tried different solutions enable cors, without success.

app.js

var myapp = angular.module('myapp', [     'ngroute',     'mycontrollers' ]);  myapp.config(function($httpprovider) {     //enable cross domain calls     $httpprovider.defaults.usexdomain = true;      //remove header used identify ajax call  prevent cors working     delete $httpprovider.defaults.headers.common['x-requested-with']; }); 

controllers.js

/* controllers */ var mycontrollers = angular.module('mycontrollers', []);  mycontrollers.controller('navigationcontroller', ['$scope', '$http',   function ($scope, $http) {     $http.get('json/data.json').success(function(data) {       $scope.data = data;     });   }]); ... 

error in console

xmlhttprequest cannot load file:///.../json/data.json. cross origin requests supported http.

any appreciated, have make app running on chrome , ie well, without running on local server.

i had this. in end had put data objects directly in script file , load in other scripts. way app didn't need make ajax requests cors didn't come it.

it's not ideal - worked....


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -