jquery ajax登录提交 页面跳转
location.href 这个赋值以后就会页面跳转了。
<form> <input type="password" name="password" id="password"/> <input type="hidden" name="password1" id="password1"/> <input id="s" type="submit" value="Submit"/> </form> <script> $(function(){ $("form").submit(function() { var v=$.md5($("#password").val()); $("#password1").val(v); $("#password").attr("disabled", "true"); return true; }); }); </script>
浏览器缓存会记住原来的值,到时候会进行N次MD5加密,所以把明文的,和加密的分开
tr 一行 td是一个数据 th 是数据头
$("#loginForm").submit(function(event){ event.preventDefault(); // Get some values from elements on the page: var $form = $( this ), account = $form.find( "input[name='account']" ).val(); $password = $form.find("input[name='password']"); $password.attr("disable",true); loginType = $form.find("input[name='loginType']").val(); password = $.md5($password.val()); loginForm = { account:account, password:password, loginType:loginType }; url = $form.attr( "action" ); function jump (data,textStatus,jqXHR){ console.log(data); console.log(textStatus); console.log(jqXHR.getResponseHeader("Set-Cookie")); if(data.Success){ //$.cookie("Gsessionid",jqXHR.getResponseHeader("Set-Cookie")); location.href="/student/"+account; }else{ $("#loginErr").fadeIn(300); } console.log(document.cookie); }; $.ajax({ type: "POST", url:url, data:loginForm, dataType:'json', success:jump }); });
模拟登录的方法,一开始不知道为什么就不带cookie了,现在浏览器又自己会管cookie了,尴尬。