简体   繁体   中英

I'm having a cannot POST when attempting to submit a form with JS

I am having an issue with my Javascript and HTML where when I submit my form, I get a Cannot POST error. I already looked at Shows error "Cannot POST" when I try to submit the HTML form , but that seems to be server-based. I'm sorry, but I'm doing this for a class, so I'm in a bit of a time crunch right now.

My login JS code:

function login(){
    var pw = document.forms['login']['passcode'].value;
    var email = document.forms['login']["email"].value;
    var login = userLogin().get();
    if(email == "adrian@tissue.com" && pw == "welcome1"){
        window.location = "issues.html";
    }
    else if(email == "admin@tissue.com" && pw == "admin123"){
        window.location = "subscription-dashboard.html"
    }
    else if(email == login[0] && pw == login[1]){
        window.location = "issues.html";
    }
    else{
        alert("That password/email is incorrect");
        return false;
    };
}

My module for get is:

(function userLogin(){
return {
    store: function(password, email){
        sessionStorage.setItem(pass, password);
        sessionStorage.setItem(user, email);
        return false;
    },
    get: function(){
        var mail = sessionStorage.getItem(user);
        var pwkey = sessionStorage.getItem(pass);
        var loginfo = [mail, pwkey];
        return loginfo;
    }
}
});

And my HTML code is:

<form action="#" name="login" method="post" onsubmit="return login()">
        <input type="text" name="email" placeholder="Email" required>
        <input type="password" name="passcode" placeholder = "Password" required>
        <input type="submit" value="login">
</form>

Here's my fiddle for ease. I'm using Brackets and this class is Client side JS. https://jsfiddle.net/MiguelPi/nmp6oxat/1/

Seems like you are trying to access to an anonymous function, rewrite userFunction like this (without external parentheses):

function userLogin(){
  return {
    store: function(password, email){
      sessionStorage.setItem(pass, password);
      sessionStorage.setItem(user, email);
      return false;
    },
    get: function(){
      var mail = sessionStorage.getItem(user);
      var pwkey = sessionStorage.getItem(pass);
      var loginfo = [mail, pwkey];
      return loginfo;
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM