Home > front end >  In the HTML page after login, the login button is show the location of the personal information, but
In the HTML page after login, the login button is show the location of the personal information, but

Time:10-07

JS code is as follows, after the login page can show the information to log in, but a refresh the page to login again

$(function () {
//hide error message
$(" # loginTip "). Hide ();
$(" # verifyTip "). Hide ();

$(" # showInfo). Hide ();

//refresh login authentication code
$(" # vCodeImg "). Click (function () {
Var SRC="http://localhost:8080/bbs/servlet/VerifyCodeServlet";
Var date=new date (). GetTime ();

$(" # vCodeImg "). Attr (" SRC ", $(" # vCodeImg "). Attr (" SRC ") + "?" + date);
})


//get the submit button, and the binding click event
$(" # logBtn "). Click (function () {
Var loginEmail=$(" # loginEmail "). Val ();
Var loginPwd=$(" # loginPwd "). Val ();
Var verifyCode=$(" # verifyCode "). Val ();

$. Ajax ({
Type: "POST",//the type of the request (GET or POST)
Url: "http://localhost:8080/bbs/servlet/UserLoginServlet", and send the requested url//specified, the default for the current page

//Ajax cross-domain access
XhrFields: {
WithCredentials: true
},

//of data to be sent to the server specified
Data: {
"LoginEmail" : loginEmail,
"LoginPwd" : loginPwd,
"VerifyCode" : verifyCode
},

DataType: "json",//the desired server returns the data type of the

Success: the function (data) {//request is successful, the server returned to normal results

The console. The log (JSON. Stringify (data));//converts JSON object to a string
The console. The log (data. EmailData);//get the value of the attribute in the JSON object

//according to the background the returned result set message
Var p=$(" # loginTip ");
Var ep=$(" # verifyTip ");


If (data. VerifyError=="error") {
Ep. The show ();
Ep. The text (" authentication code input is wrong ");
}
Else if (data loginInfo! {
="")
Var email=JSON. Stringify (data);
Alert (" login successful!" );
$(" # login "). Modal (" hide ");//login successfully closed after login popup window
//$(" # login_register "). Hide (); Register/login/hide button
$(" # login_register "). The remove ();

$(" # loginInfo "). The text (" welcome back: "+ email);
$(" # showInfo "). The show ();
}
Else if (data. The result=="fail") {
//logon failure information
P. how ();
P.t ext (" email address or password you entered is wrong ");
}

//when the password input box gains focus again, hidden error message
Var pwdElt=document. GetElementById (" loginPwd ");
PwdElt. An onfocus=function () {
P.h ide ();
pwdElt.valuehttps://bbs.csdn.net/topics/="";
}

//when captcha input box gains focus again, hide the error message and empty input box
Var verifyElt=document. GetElementById (" verifyCode ");
VerifyElt. An onfocus=function () {
Ep. Hide ();
verifyElt.valuehttps://bbs.csdn.net/topics/="";
}


},
Error: function (errorData) {//request fails, the server is not normal to return as a result, the server goes down, abnormal daemon
Alert (" server exception! Please try again later ");
}

});

});

});



CodePudding user response:

1, if you're a landing page now and a landing interface, then refresh the page after reset is normal;
2, I think your idea is to display user information after login, refresh also shows the information just now, after that you request after the success you need to put the user information is preserved (sseionstorge, etc.), in the current page load time have to do is read, add judgment when the page is loaded, if sseionstorge have user information is read and display user information, if there is no information is displayed on the UI,
  •  Tags:  
  • Ajax
  • Related