Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
XMLHttpRequest cannot load url. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response

I decided to upload my html5 game to Facebook platform, but I have a problem with the requests to my api/server because now requests come from a different domain (https://apps.facebook.com/mygame).

I have received this error:

XMLHttpRequest cannot load https://myurl/api/login. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

This is my AJAX request:

function login(token)
{

  $.ajax({
     url: 'https://myurl/api/login',
     method: 'get',
     headers: {"Authorization": "Bearer " + token},
     contentType: "application/json",
     beforeSend: function(xhr) {
       xhr.setRequestHeader("Authorization", "Bearer " + token);
     },                        
     success: function(data, textStatus, jqXHR) {
        // To next state
     },
     error: function (jqXHR, textStatus, errorThrown) {
        // Error
     }
  });
}

The requests from my server works, but from facebook it doesn't, this is my .htaccess file:

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>

The API is done with slim framework (php) and my server is Apache. I've tried a lot of options like setting the headers in the .htaccess or in the AJAX requests, but I don't achieve it. How could I do it?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda