0

I am getting the following error while calling one REST API to get the data using Angular.js.

Error: Failed to load http://13.232.74.71:8081/get/all_hotels: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.25.25.100' is therefore not allowed access.

I am providing my code below.

homeController.js:

var dashboard=angular.module('bookingjini');
dashboard.controller('homeController',function($scope,$http,$state,$window,DataService){
    $scope.hotelDetailsArr=[];
    var url='http://13.232.74.71:8081/get/all_hotels';
    var method='GET';
    var data='';
    DataService.connectToServerSideScript(method,url,data)
    .then(function(response) {
        $scope.hotelDetails=response.Data;
        angular.forEach($scope.hotelDetails,function(obj){
            $scope.hotelDetailsArr.push(obj.Record);
        })
    },function(error) {

    })
})

route.js:

Admin.factory('DataService', DataService);
function DataService($http, $q){
    return{
        connectToServerSideScript:connectToServerSideScript
    }
    function connectToServerSideScript(method,url,userData){
        //console.log('deffered',method,url,userData);
        var deferred = $q.defer();
        $http({
            method:method,
            url:url,
            data:userData,
            headers: { 'Content-Type': 'application/json' }
        }).then(function(response) {
            //console.log('data defer',response.data);
            deferred.resolve(response.data);
        },function(error) {
            deferred.reject(error.data);
        })
        //console.log('data defer',deferred.promise);
        return deferred.promise;
    }

}

Here I am trying access the data via that API url bt getting the above error. I had also added Allow-Control-Allow-Origin: extension yesterday and it was working but today again the same error came.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • Be sure CORS extension is enabled when http call is performing – Irvin Sandoval Jul 06 '18 at 06:47
  • Can you please tell me how it can be enabled ? – satya Jul 06 '18 at 06:50
  • Click on the CORS icon on your browser then enable the *Enable cors-origin resource sharing* option, the CORS icon should becoming green. – Irvin Sandoval Jul 06 '18 at 07:03
  • @IrvinSandoval : I did that but still same issue. – satya Jul 06 '18 at 08:33
  • Note we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Jul 07 '18 at 22:59
  • In particular, you are persisting with a please-halp-me-sir form of pleading (you still have 135 of these in your post history). [I have argued here](https://meta.stackoverflow.com/q/366264) that this may be a poor long-term strategy for nervous developers wanting to use Stack Overflow to its full potential. While there will sometimes be short-term gains for asking readers to afford you some pity, you may find this harms your skills confidence in the long term, since you have persuaded yourself that you cannot be self-sufficient – halfer Jul 07 '18 at 23:03
  • I have commented on three of your questions before, in my capacity as a volunteer editor, asking for brevity, and I have not yet seen a reply from your side. Would you please help me? – halfer Jul 07 '18 at 23:06

1 Answers1

0

You might need to enable CORS in your back-end API.

Lemuel Castro
  • 166
  • 11