JSP頁面ajax提交登入資料demo

來源:互聯網
上載者:User

標籤:style   http   io   ar   os   sp   java   for   strong   

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>登入頁面</title><link rel="stylesheet" href="${pageContext.request.contextPath}/style/reset.css"><link rel="stylesheet" href="${pageContext.request.contextPath}/style/login.css"><script src="${pageContext.request.contextPath}/js/lib/jquery-1.9.1.min.js"></script><script src="${pageContext.request.contextPath}/js/lib/AntMove.js"></script><script>$(function(){$("#btn").click(function(){var $_login = $("#loginForm").get(0);var $_tip = $("#tip").get(0);/*  */var userName = $(".userName");var password = $(".password");var tip = "";if( $.trim( userName.val() ) == "" ){tip = "帳號不可為空";userName.focus();}else if( !/^\w{5,20}$/.test( userName.val() ) ){tip = "帳號長度必須5-20之間";userName.focus();}else if($.trim( password.val() ) == ""){tip = "密碼不可為空";password.focus();}if(tip != ""){ //如果tip有值提示錯誤資訊alert(tip);}else{ //發送ajax請求$.ajax({url:"${pageContext.request.contextPath}/loginAjax.action",//ajax的請求地址type:"post",//請求方式dataType:"json",//返回資料為jsondata:$("#form").serialize(), //$("#loginForm").serialize() 序列化async:true, //是否非同步 true為非同步,false為同步success:function(data){ //非同步成功回調console.log(data);if(data.success == "1"){alert(data.tip);window.location = "${pageContext.request.contextPath}/index.action";}else if(data.success == "0"){antMove($_login,{top:60},1000,"elasticOut",function(){$(".tip").css("display","block");antMove($_tip,{top:0},1000,"elasticOut");});}},error:function(msg){ //ajax失敗回調alert("ajax發送失敗:"+msg);}});}});});</script></head><body><div id="login"><!-- <div class="logo">    <a href=""><img src="${pageContext.request.contextPath}/images/logo.png"></a>    </div> -->    <div class="tipParent">        <div id="tip" class="tip">            <strong>錯誤 : </strong>            <span>無效使用者名稱。</span>            <a href="">忘記密碼?</a>        </div>    </div>    <div class="formParent">        <div id="loginForm" class="loginForm">            <form id="form">                <div class="loginName">                    <label>使用者名稱</label>                    <input type="text" value="admin" class="userName" name="userName">                </div>                <div class="loginPassword">                    <label>密碼</label>                    <input type="text" class="password" name="password">                </div>                <div class="loginBtn">                    <input type="checkbox">                    <span>記住我的登入資訊</span>                    <input type="button" value="" class="btn" id="btn">                </div>            </form>        </div>    </div></div></body></html>


JSP頁面ajax提交登入資料demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.