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

151
Visualizações
How to listen to 302 server response

I am trying to achieve the following. After a form is submitted successfully I want to run a code after the server response is 302. for this example, I have a form that is waiting to be submitted, after a successful submission the server returns a 302 response. I am trying to listen to this response so I can run a code snippet after the 302 response. This is what I have done so far:

var posts = new XMLHttpRequest();
  posts.onreadystatechange = function() {
    if (posts.status == 302) { 
      alert("succesfull")
    }
  }
  posts.open("POST", "http://127.0.0.1:8000/", true);
  posts.send();

This does not work, can someone explain why?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you are missing readyState in if condition which holds the status of the XMLHttpRequest.

try to modify your code like below:-

function loadDoc() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            alert('passed!')
       }
    };
    xhttp.open("POST", "http://127.0.0.1:8000/", true);
    xhttp.send();
}

readyState 4 means request finished and response is ready.

about 4 years ago · Juan Pablo Isaza Relatório
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