This article mainly introduces how to determine whether to log on by js and determine whether to jump to the page. It involves Ajax and session skills and is very useful, for more information about how to determine whether to log on with js and redirect to the page, see the example in this article. Share it with you for your reference. The details are as follows:
Use session storage to determine whether the user is logged on, so as to determine the page to which the page is redirected.
Check whether there is a local mermerid:
function jumpTo(p, url) { var customerId=sessionStorage.customerId; if (customerId == undefined) { p.attr("href", "page/Login/login.html"); } else { p.attr("href", url); } } function infoJumpTo() { var $info = $("#info"); jumpTo($info, "http://localhost/page/AmountAscension/amountAscension.html"); } function starJumpTo() { var $star = $("#star"); jumpTo($star, "http://localhost/page/MyAccount/myAccount.html"); }
In html, write onclick = "infoJumpTo" in the corresponding a tag.
But how does the customerID on the login page be stored in the local session?
Function confirm () {var tel = $ tel. val (); // obtain the logon name and password var pwd = $ pwd on the page. val (); if (tel = "" | pwd = ") {// both judgment rules are not empty (other judgment rules have been determined when they are input) alert ("No. And no password can be blank! ") Return false;} else {// if all the preceding conditions are met, the logon esb interface $. ajax ({url: config. baseServerUrl + '/account/login', // type: 'post', data: {mobile: tel, password: pwd }, // success: function (data) passed to the server (Interface) {// The data returned by the server (Interface) if (data. success) {// If the returned information indicates that the submitted information is correct var customerId = data. attr. customerInfo. id; // assign the user information ID in the data to the sessionStorage variable. customerId = customerId; // store the variable to the local sessionStorage, and the value is customerID window. location. href =' http://localhost/index.html '; // After correct logon, the page jumps to} else {// if the returned information indicates that the provided information is incorrect if (tel! = Data. tel) {// determines whether the user name or password is incorrect, and the corresponding information alert (data. message); $ tel. val (""); $ pwd. val (""); return false;} if (pwd! = Data. pwd) {alert (data. message); $ pwd. val (""); return false ;}}}})}}
On the logon page, people usually get used to entering information and click enter to manually click the logon button. The js Code is as follows:
// Determine whether the Enter key is hit $ (document ). keyup (function (event) {if (event. keyCode = 13) {$ ("# login "). trigger ("click ");}});
I hope this article will help you design javascript programs.