Processing of garbled code During js submission at noon: encodeURI URLDecoder, jsencodeuri
Keywords: js url Chinese garbled characters
Front-end code:
Function login () {$ ('# error_msg '). hide (); var uname = $ ("# name "). val (); var pwd = $ ("# password "). val (); if (uname = "" | uname = "username") {$ ('# error_msg '). text ('user name or password cannot be blank! '); $ (' # Error_msg '). show (); return false;} if (pwd = "" | pwd = "password") {$ ('# error_msg '). text ('user name or password cannot be blank! '); $ (' # Error_msg '). show (); return false;} $. getJSON ("user/login", {loginName: encodeURI (uname), password: md5 (pwd), passwordwy: pwd, ran: Math. random ()}, function (result) {if (result. flag = "false") {$ ('# error_msg '). text (result. returnMsg); $ ('# error_msg '). show (); return;} else {Cookie. setcookie ("userName", result. returnMsg); Cookie. setcookie ("loginID", result. loginId); Cookie. setcookie ("userId", result. id); window. location. href = "index.html ";}});}
Background code:
String loginId = request.getParameter("loginName");try {loginId = URLDecoder.decode(loginId,"UTF-8");} catch (UnsupportedEncodingException e1) {e1.printStackTrace();}