0

I am calling a restful sharepoint 2010 service via Angular JS as following but when I run the application I always get the "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." error. NOTE: If I try the same GET method from my local machine via Chrome POSTMAN tool the same call works. What am I doing wrong?

var myApp = angular.module('MyApp', []);
myApp.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
myApp.controller('MYCtrl', function($scope, $http) {
var site = 'http://inside.company.net/it/gsst/private/_vti_bin/listdata.svc/CCPMGAST';
$http({
  method: 'GET',
  withCredentials: true,
  url: site,
  headers: { "Accept": "application/json; odata=verbose" }
  }).success(function (data, status, headers, config) {
    $scope.getCallJSONResult = data;
  }).error(function (data, status, headers, config) {
    $scope.getCallJSONResult = "Get error";
  });
});
  • You have a local webSite on your local IIS ? What Browser do you use ? Try with IE. – Max Mar 25 '15 at 12:16
  • idea is that it will be a client single page app and it can access the sharepoint farm and will also have some offline capabilities. Thus all the code on the client once I get the data. – Qammer Adil Mar 25 '15 at 13:50
  • OK. I tried IE and this same code is working. But I am stiff curious why the same request works with Chrome Postman and not in my code? – Qammer Adil Mar 26 '15 at 16:24
  • Security [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) problem. On Chrome (and Firefox) you can't do REST to be requested from another domain outside the domain from which the resource originated. You can [temporary disable the functionality on Chrome](http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome) this allow GET request but NOT the POST request. By the way I have the same problem and I'm still looking for an answer. POSTMAN work because the call is not originated from a browser but from a program. – Max Mar 26 '15 at 17:25

0 Answers0