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?