(23)ExtJS之表单数据异步提交

JS文件:

//1:表单数据异步提交
Ext.onReady(function(){

		Ext.QuickTips.init();
		var loginForm=Ext.create('Ext.form.Panel',{
			
			title:'表单提交示例',
			width:230,
			frame:true,
			fieldDefaults:{
				labelSeparator:':',
				labelWidth:50,
				msgTarget:'side',
				width:200
			},
				renderTo:Ext.getBody(),
				bodyPadding:5,
				defaultType:'textfield',
				items:[{
					fieldLabel:'用户名',
					name:'userName',
					allowBlank:false,
					vtype:'email'
				},{
					fieldLabel:'密码',
					name:'password',
					inputType:'password',
					allowBlank:false
				}],
				buttons:[{
					text:'登录',
					handler:login
				},{
					text:'重置',
					handler:reset
				}]
	
		});
		function login(){//提交表单
				loginForm.getForm().submit({
					clientValidation:true,//进行客户端验证
					url:'012_loginServer.jsp',//请求的url地址
					method:'GET',//请求方式
					success:function(form,action){//加载成功的处理函数
						
						Ext.Msg.alert('提示','系统登陆成功');
					},
					failure:function(form,action){//加载失败的处理函数
						Ext.Msg.alert('提示','系统登录失败,原因:'+action.failureType);
					}
					
				});
		}
			function reset(){//重置表单
				logiNForm.form.reset();
			}
});

012_loginServer.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP '012_loginServer.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<%
	String password=request.getParameter("password");
	String msg="";
	if(password.length()<6){//密码不足六位验证失败
			msg="{success:false,errors:{password:'密码不得小于六位数字'}}";
	}else{//验证成功
		msg="{success:true}";
	}
	response.getWriter().write(msg);

%>
  </body>
</html>

访问的jsp文件:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'JS1.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!-- extjs的样式文件 -->
	<link rel="stylesheet" type="text/css" href="js/extjs/resources/css/ext-all.css">
	<!-- extjs的核心文件 -->
	<script type="text/javascript" charset="utf-8" src="js/extjs/ext-all-debug.js"></script>
	<!-- 国际化文件 -->
	<script type="text/javascript" charset="utf-8" src="js/extjs/ext-lang-zh_CN.js"></script>
	
	<script type="text/javascript" charset="utf-8" src="base/012_form_login.js"></script>

  </head>
  
  <body>
  </body>
</html>



你可能感兴趣的:((23)ExtJS之表单数据异步提交)