Ajax Status == 0

Asked

Viewed 353 times

2

I’m using a function in ajax to make some dynamic requests, but the 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;
   }
  • Some of these answers answered him?

  • No. The mistake was another.

  • I could post what it was?

1 answer

1

What might be going on:

  1. Cross-site scripting CORS (you are trying to access a URL from different from the application)
  2. The URL may be inaccessible.
  3. You may be using the wrong protocol, many times we may be testing using the protocol file:\\\ instead of localhost:\\.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.