Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!