ExtJs表单提交
Ext.QuickTips.init(); Ext.BLANK_IMAGE_URL = 'js/ext3/resources/s.gif'; Ready(function(){ var loginForm = new Ext.FormPanel({ frame:true, method:'POST', border:false, formId:'form1', name:'form1', //ptyFn, //submit: function(){ //El().dom.action = 'common/ajax/login.jsp'; //连接到服务器的url地址 //El().dom.submit(); //El().dom.elements.length); //}, defaults:{ xtype:'textfield', anchor:'90%' }, items:[{ name:'username', id:'username', fieldLabel:'用户名' },{ name:'password', inputType:'password', fieldLabel:'密码' },{ name:'code', fieldLabel:'验证码', anchor:'50%' }], buttons:[{ text:'登录', type:'submit', //第三种方式 handler:function() { quest({ url:'common/ajax/login.jsp', method:'POST', params:{ 'username':Ext.get("username").dom.value }, success:function(form, action) { var text = eval("("+sponseText+")"); alert('--------------2=' + text.msg); }, failure:function() { alert('--------------1'); } }) } //第二种方式 /* handler:function() { loginForm.form.doAction('submit', { url:'/ext/common/ajax/login.jsp', method:'POST', params:'', success:function(form, action) { //sult); if (sult.msg == 'ok') { //document.location='index.html'; Ext.Msg.alert('成功', sult.msg); } else { Ext.Msg.alert('登陆错误', sult.msg); } }, failure:function(form, action) { Ext.Msg.alert('警告', '用户名或密码错误!'); } }) }*/ //第一种方式 //handler:function() { //loginForm.form.submit(); //} },{ text:'取消', handler:function() { set(); } }] }); var win = new Ext.Window({ title:'window', width:400, frame:true, border:false, modal:true, resizable:false, items:loginForm }); win.show(); }); |
1、 正常form提交
这种方式需要在FormPanel对象中增加属性
ptyFn, submit: function(){ this.getEl().dom.action = 'common/ajax/login.jsp'; //连接到服务器的url地址 this.getEl().dom.submit(); alert(this.getEl().dom.elements.length); }, |
提交按钮:
handler:function() { loginForm.form.submit(); } |
2、 默认提交方式(Ajax)
默认的提交方式:
handler:function() { loginForm.form.doAction('submit', { url:'/ext/common/ajax/login.jsp', method:'POST', params:'', success:function(form, action) { //sult); if (sult.msg == 'ok') { //document.location='index.html'; Ext.Msg.alert('成功', sult.msg); } else { Ext.Msg.alert('登陆错误', sult.msg); } }, failure:function(form, action) { Ext.Msg.alert('警告', '用户名或密码错误!'); } }) } |
服务端代码:
request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); String username = Parameter("username"); System.out.println("---->>>>>" + username); out.print("{success:true, msg:'ok'}"); |
3、 Ext的Ajax提交
Ext的ajax提交:
handler:function() { quest({ url:'common/ajax/login.jsp', method:'POST', params:{ 'username':Ext.get("username").dom.value }, success:function(form, action) { var text = eval("("+sponseText+")"); alert('--------------2=' + text.msg); }, failure:function() { alert('--------------1'); } }) } |
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论