0

Im relative new to JavaScript/WebDevelopment.

I need to implement a basic Forgot Password feature for an app. Currently the workflow is like this:

  • endpoint gets called, sends token as email to user
  • user clicks, my website gets called with get parameter tok=GENERATED_TOKEN
  • now, after the user has typed in the password+confirmation, he clicks submit and I do a XMLHttpRequest from javascript to send the token+password to my endpoint

the code for this looks like this

var request = new XMLHttpRequest();
request.onreadystatechange = function() {
    if (request.readyState == 4) {
        window.location.href = "https://www.mydomain.io/password-change-success.html";
    }
}
request.open("GET", url, true);
request.send(null);

The problem im encountering is that I want to check if the request was done successfully, the server sends a confirmation text when the password has changed. I have confirmed with Postman that the endpoint actually gets called. And this javascript snippet also successfully calls the endpoint (verified with debugging).

But request.status is always 0, so I cant check if my server sends back code 200 (success) and the responseText is also empty.

Researching showed me that this might be a problem of a CORS-Header.

For my endpoint I am using Spring, hosted on staging.mydomain.io, and the web server is on mydomain.io.

Derlin
  • 9,572
  • 2
  • 32
  • 53

0 Answers0