0

I have an AJAX login request that calls a PHP File which processes the request data and echo if the login is successful or not. The JS script doesn't receive any values from the request Here is the code:

document.getElementById("Login-Accedi-Btn").addEventListener("click", (event) => {
  var xmlHttp = new XMLHttpRequest();
  loginusernameinput = document.getElementById("Login-Username-Input").value;
  loginpasswordinput = document.getElementById("Login-Password-Input").value;
  if (loginusernameinput == "" || loginpasswordinput == "") {
    loginerror("Errore: Username o Password vuoti");
  }
  xmlHttp.open("GET", "logincheckajax.php?user=" + loginusernameinput + "&password=" + loginpasswordinput, true);
  xmlHttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      loginstatus = xmlHttp.responseText;
      if (loginstatus == "Corretto") {
        window.reload;
      } else {
        if (loginstatus = "SbagliatoUserOPassword") {
          loginerror("Errore: Username o Password non corrispondenti")
        } else {
          if (loginstatus = "UsernameOPasswordNonSettati") {
            loginerror("Errore: Username o Password non rilevati nell'autenticazione");
          } else {
            loginerror("Errore non definito");
          }
        }
      }
    }
  }
})
ThS
  • 4,597
  • 2
  • 15
  • 27
lorek006
  • 29
  • 4
  • In general, an interactive [debugger](/q/25385173/90527) is your most powerful tool in cases like this, for troubleshooting unexpected behavior. Browsers provide many debugging tools, including one that lets you inspect network requests, which should be one of the first things to check when there's an issue with requests or responses. – outis Oct 09 '22 at 22:40
  • Does this answer your question? [How to make a GET Request in XMLHttpRequest?](/q/56796041/90527) – outis Oct 10 '22 at 06:23

1 Answers1

1

You must call send to actually send the request.

You might want to look into the newer fetch API as it can be simpler to set up and use.

outis
  • 75,655
  • 22
  • 151
  • 221