JQUERY 表单异步提交

<!doctype html>
<html lang="en">
<head runat="server">
  <meta charset="UTF-8">
    <title>JQUERY 表单异步提交</title>
    <!-- JQUERY 类库 -->
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
    $(document).ready(function()
        {
            $('#myform').submit(function(){
                jQuery.ajax({
	                url: "/ajaxjsonform",   // 提交的页面
                    data: $('#myform').serialize(), // 从表单中获取数据
                    type: "POST",                   // 设置请求类型为"POST",默认为"GET"
                    beforeSend: function()          // 设置表单提交前方法
                    {
						//提交过程中锁屏
                        new screenClass().lock();
                    },
                    error: function(request) {      // 设置表单提交出错
						//提交完成后无论成功与否都解除锁定
                        new screenClass().unlock();
                        alert("表单提交出错,请稍候再试");
                    },
                    success: function(data) {
						//提交完成后无论成功与否都解除锁定
                        new screenClass().unlock(); // 设置表单提交完成使用方法
                    }
                });
                return false;//前台测试用
                //return true;//生产环境
            });
        });

    var screenClass = function()
    {
        /// 解锁
        this.unlock = function()
        {
            var divLock = document.getElementById("divLock");
            if(divLock == null) return;
            document.body.removeChild(divLock);
        };

        /// 锁屏
        this.lock = function()
        {
            var sWidth,sHeight;
            var imgPath = "wait.gif";
            sWidth  = screen.width - 20;
            sHeight = screen.height- 170;

            var bgObj=document.createElement("div");
            bgObj.setAttribute("id","divLock");
            bgObj.style.position="absolute";
            bgObj.style.top="0";
            bgObj.style.background="#cccccc";
            bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
            bgObj.style.opacity="0.6";
            bgObj.style.left="0";
            bgObj.style.width=sWidth + "px";
            bgObj.style.height=sHeight + "px";
            bgObj.style.zIndex = "100";
            document.body.appendChild(bgObj);
            var html = "<table border=\"0\" width=\""+sWidth+"\" height=\""+sHeight+"\"><tr><td valign=\"middle\" align=\"center\"><image src=\""+imgPath+"\"></td></tr></table>";
            bgObj.innerHTML = html;
            // 解锁
            bgObj.onclick = function()
            {
                 //new screenClass().unlock();
            }
        };
    }
    </script>
</head>

<body>
    <form id="myform" runat="server">
    <div>
        姓名:<input type="text" id="txtUsername" name="txtUsername" value=""><br />
        年龄:<input type="text" id="txtAge" name="txtAge" value=""><br />
        备注:<input type="text" id="txtDescription" name="txtDescription" value=""><br />
        候时:<input type="text" id="txtWaitTime" name="txtWaitTime" value=""><br />
        <input type="submit" id="btnSubmit" name="btnSubmit" value="提交">
    </div>
    </form>
</body>
</html>


转自:http://www.cnitblog.com/hj627/articles/61395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值