Ajax Status == 0

2

I'm using a function in ajax to make some dynamic requests, but req.status is returning 0 instead of 200 .

What can it be?

Below the code:

   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);

   // 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 == 1) {      
        alert("Entrei no readyState == 1");
     }
     if(req.readyState == 4 && req.status == 200) {
         alert("Entrei no readyState == 4 e status == 200");
         // Resposta retornada pelo busca.php
         var resposta = req.responseText;
   }
    
asked by anonymous 06.05.2015 / 20:34

1 answer

1

What may be happening:

  • Cross-site scripting CORS (you are trying to access a URL from different domain from the application)
  • The URL may be inaccessible.
  • You may be using the wrong protocol, we can often be testing using the file:\\ protocol instead of localhost:\ .
  • 06.05.2015 / 21:13