Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

REST service No 'Access-Control-Allow-Origin' #5009

@ivanntis

Description

@ivanntis

I have an application made ​​only with html5, css3 and AngularJS, and by consuming a REST service from a local server the following error
XMLHttpRequest cannot load http://127.0.0.1:3080/wsLunch/authentication/ivan/Ricardo**. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access.

and I could not solve,Thanks for your help

////////////////////////app.js///////////////////////////

var offerApp = angular.module('offerApp', [
  'ngRoute',
  'offerControllers',
  'offerServices'
]);


offerApp.config(['$routeProvider',
  function($routeProvider) {

    $routeProvider.
      when('/exmapleAngulaJS', {
        templateUrl: '/examples/exmapleAngulaJS.html',
        controller: 'offerListCtrl'
      }).
      otherwise({
        redirectTo: '/examples/exmapleAngulaJS'
      });
  }]);

///////////////////////////controller.js///////////////////////////

var offerControllers = angular.module('offerControllers', ['ngResource','offerServices']);

offerControllers.controller('offerListCtrl',['$scope','Offer',  function ($scope,Offer) {
    console.log("Offer.controller");
    $scope.offers = Offer.query();     
}]);

///////////////////////////serviceRest.js///////////////////////////

var offerServices = angular.module('offerServices', ['ngResource']);

offerServices.factory('Offer', ['$resource',function($resource){      
         return $resource('http://127.0.0.1:3080/wsLunch/authentication/ivan/Ricardo', {}, {                    query: {method:'GET', params:{}, isArray:true}                   
                });           
  }]);

////////////////////exampleAngular.html///////////////////////

<html ng-app="offerApp">
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script src="http://code.angularjs.org/1.2.0/angular.min.js"></script>
  <script src="http://code.angularjs.org/1.2.0/angular-route.js"></script>
   <script src="http://code.angularjs.org/1.2.0/angular-resource.js"></script>
  <script src="app.js"></script>
   <script src="serviceRest.js"></script>
  <script src="controller.js"></script>
  <link rel="stylesheet" type="text/css" href="panelSeriesCSS.css">
</head>
<body ng-controller="offerListCtrl">
    <section>        
        <div class="contenedor">
        <div id="panelItemOffer" class="panelSeriesClass"  ng-repeat="offer in offers">
              <div id="titleOffer" class="panelTittleClass">
                  <span>
                      {{offer.id}}
                  </span>
              </div>
           <div id="contenctOffer" class="panelContectClass">
                 <img id="imageOffer" src="{{offer.img}}"/>
                 <div id="descriptionOffer">
                     <p id="TextAreaDescription">
                          {{offer.desc}}
                     </p>
                  </div>
          </div> 
            </div>      
    </div>
      </section>
</body>
</html> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions