Ajax be submitted using the form, simple login

Front-end code

<form id="loginForm"  onsubmit="return false" action="##" method="post">
    <input type="text" name="userName" class="username" placeholder="Username">
    <input type="password" name="password" class="password" placeholder="Password">
    <button type="button" onclick="loginNow()">Sign me in</button>
    <div class="error"><span>+</span></div>
    <P id = "passwordTip" style = "visibility: hidden"> Error code </ p>
</form>

code portion ajax

function loginNow() {
     $.ajax({
        
         type:"POST",
         url:"/login",
         data:$("#loginForm").serialize(),
         dataType:"json",
         success:function (result) {
             if(result==true){
                 // alert ( "Success")
                 window.location.href="/notifications"
             }else{
                document.getElementById("passwordTip").style.visibility="visible"
                 // alert ( "password")
             }
         }
     })
 }

After the rear end is the username and password match, returns a Boolean value json format, verify distal end to perform before and after separation

 

 

Guess you like

Origin blog.csdn.net/abc_123456___/article/details/88993065