1

I have some jQuery that fetches data and executes a callback:

$(function(){
$.ajax({
    type: 'POST',
    url: 'http://flash-cast-hrd.appspot.com/api/sonar/sync', 
    data: {
        source: 5,
        auth: 'JXEI....DHA2J'
    }, 
    success: displayData
});
});

I am trying to make the same request from my angular controller, where I have a method on the scope.

$scope.init = function(){

            $http.post('http://flash-cast-hrd.appspot.com/api/sonar/sync', {
                source: 5,
                auth: 'JXEI....DHA2J'
            })
                .success(function(data){
                    console.log(data);
                })
                .error(function(error){
                    console.log('Error is: ' + error);
                });
        };

Then call it in a view:

<div ng-init="init()"></div>

When I load the page I get an error in the console:

OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync 405 (Method Not Allowed) angular.js:8021
OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. angular.js:8021
XMLHttpRequest cannot load http://flash-cast-hrd.appspot.com/api/sonar/sync. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. :8000/routes:1
Error is:  

How can I make the angular $http.post request work?

Connor Leech
  • 18,052
  • 30
  • 105
  • 150

1 Answers1

0

Issue is because of cross domain access, You can overcome by setting proxypass on your server and your request needs to include Access-Control-Allow-header also.

Fidel
  • 977
  • 1
  • 6
  • 13