Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

518
Views
AngularJS: No hay encabezado "Access-Control-Allow-Origin" presente en el recurso solicitado

Estoy escribiendo mi aplicación web y estoy usando AngularJS. En esta aplicación he creado un archivo llamado script.js y reporto este código:

 var modulo = angular.module('progetto', ['ngRoute']); // configure our routes modulo.config(function ($routeProvider, $httpProvider) { $routeProvider // route for the home page .when('/', { templateUrl: 'listaFilm.html', controller: 'listaController' }) // route for the description page .when('/:phoneName', { templateUrl: 'description.html', controller: 'descriptionController' }); $httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = '*'; }); modulo.controller('listaController', function ($scope, $http) { $http.get('https://api.getevents.co/event?&lat=41.904196&lng=12.465974').success(function (data) { $scope.names = data; }). error(function (data, status) { $scope.names = "Request failed"; }); });

Con este código llamo a la API siguiendo los principios RESTful. Cuando ejecuto el código tengo este problema:

XMLHttpRequest no puede cargar https://api.getevents.co No hay ningún encabezado 'Access-Control-Allow-Origin' en el recurso solicitado. Por lo tanto, no se permite el acceso al origen ' http://localhost:8383 '.

Leyendo en la web entendí que tengo un problema llamado CORS... He probado varias soluciones propuestas pero no resolví el problema.
¿Cómo puedo solucionar el problema?
¿Cuál es el código que debo agregar para solucionarlo?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Este es un problema del lado del servidor. No necesita agregar ningún encabezado en angular para cors. Debe agregar un encabezado en el lado del servidor:

 Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Methods: GET, POST, OPTIONS Access-Control-Allow-Origin: *

Las dos primeras respuestas aquí: Cómo habilitar CORS en AngularJs

over 4 years ago · Santiago Trujillo Report

0

CORS es Intercambio de recursos de origen cruzado, obtiene este error si está intentando acceder de un dominio a otro dominio.

Intenta usar JSONP. En su caso, JSONP debería funcionar bien porque solo usa el método GET.

Prueba algo como esto:

 var url = "https://api.getevents.co/event?&lat=41.904196&lng=12.465974"; $http({ method: 'JSONP', url: url }). success(function(status) { //your code when success }). error(function(status) { //your code when fails });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!