No 'Access-Control-Allow-Origin' header is present on the requested resource [duplicate]

3

I'm trying to do biometric authentication on a remote machine, using XMLHttpRequest. But it is returning the following message:

XMLHttpRequest can not load link . In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access

The code follows below. Does anyone know where the error is? What should I do?:

   <?php
       header('Access-Control-Allow-Origin', 'http://177.55.99.146:8080');
    ?>

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">  
    function autenticarbiometria() { 
       var fileInput = document.getElementById('fileInput');
       var file = fileInput.files[0];
       var reader = new FileReader();
       var campo = "";
       var status = "f";;

       if (file.size != 400) {
          alert("ATENÇÃO --> O arquivo selecionado NÃO está em um formato Biométrico válido!");
          return false;
       }

       if (!confirm("CONFIRMA AUTENTICAÇÃO BIOMÉTRICA NA BASE DE DADOS?")) {
          return false;
       }

       if(window.XMLHttpRequest) {
          req = new XMLHttpRequest();
          }
       else if(window.ActiveXObject) {
          req = new ActiveXObject("Microsoft.XMLHTTP");
          }

       // Arquivo PHP juntamente com o valor digitado no campo (metodo GET)
       var url = "http://177.55.99.146:8080/autenticacao/autentica?arquivo="+file;

       // Chamada do metodo open para processar a requisicao

       req.open("GET",url,true);
       req.send(null); 

       // Quando o objeto recebe o retorno, chamamos a seguinte funcao
       req.onreadystatechange = function() {
         alert("Retorno do readyState == " + req.readyState + " readyStatus == " + req.status);
         if(req.readyState == 4 && req.status == 200) {
             // Resposta retornada pelo busca.php
             var resposta = req.responseText;
             alert("ATENÇÃO --> RETORNO AUTENTICACAO = " + resposta);
          }  
        }
  }
</script>
    
asked by anonymous 19.05.2015 / 17:33

1 answer

-1

This error is because the Access-Control-Allow-Origin header is not defined on the server. This header defines that other domains can access a particular resource. See more on this in Stack Overflow: link

If you are not responsible for the service that your code is referring to, you will need to contact the person responsible to request this authorization.

    
04.08.2015 / 20:56