微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Extjs用ajax提交表单四种方式

  1. /**
  2. *<p>
  3. *第一种Ajax提交方式
  4. *</p>
  5. *<p>
  6. *这种方式需要直接使用extAjax方法进行提交
  7. *</p>
  8. *使用这种方式,需要将待传递的参数进行封装
  9. *
  10. *@return
  11. */
  12. functionsaveUser_ajaxSubmit1(){
  13. Ext.Ajax.request({
  14. url:'user_save.action',
  15. method:'post',
  16. params:{
  17. userName:document.getElementById('userName').value,92); line-height:18px"> password:document.getElementById('password').value
  18. },
  19. success:function(response,options){
  20. varo=Ext.util.JSON.decode(response.responseText);
  21. alert(o.msg);
  22. failure:function(){
  23. }
  24. });
  25. /**
  26. *第二种Ajax提交方式
  27. *这种方式将为ext的ajax指定一个html表单
  28. *使用这种方式,不需要将待传递的参数进行封装
  29. *
  30. *@return
  31. */
  32. functionsaveUser_ajaxSubmit2(){
  33. Ext.Ajax.request({
  34. url:'user_save.action',92); line-height:18px"> method:'post',255); line-height:18px"> form:'userForm',//指定表单
  35. *第三种Ajax提交方式
  36. *这种方式将为ext的自己的表单进行提交
  37. *使用这种方式,需要使用ext自己的textField组件
  38. functionsaveUser_ajaxSubmit3(){
  39. //定义表单
  40. varformPanel=newExt.FormPanel({
  41. labelWidth:75,255); line-height:18px"> frame:true,92); line-height:18px"> bodyStyle:'padding:5px5px0',255); line-height:18px"> width:350,92); line-height:18px"> defaults:{
  42. width:230
  43. },
  44. defaultType:'textfield',92); line-height:18px"> items:[{
  45. fieldLabel:'用户名',92); line-height:18px"> name:'userName',255); line-height:18px"> allowBlank:false
  46. ottom:0px!important; margin-left:0px!important; padding-top:0px!important; padding-right:3px!important; padding-bottom:0px!important; padding-left:10px!important; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:solid; border-width:initial; border-color:initial; list-style-type:decimal-leading-zero; list-style-position:outside!important; border-left-width:3px; border-left-color:rgb(108,{
  47. fieldLabel:'密码',92); line-height:18px"> name:'password'
  48. }]
  49. //定义窗口
  50. varwin=newExt.Window({
  51. title:'添加用户',92); line-height:18px"> layout:'fit',255); line-height:18px"> width:500,92); line-height:18px"> height:300,255); line-height:18px"> closeAction:'close',92); line-height:18px"> closable:false,255); line-height:18px"> plain:true,92); line-height:18px"> items:formPanel,255); line-height:18px"> buttons:[{
  52. text:'确定',255); line-height:18px"> handler:function(){
  53. varform=formPanel.getForm();
  54. varuserName=form.findField('userName').getValue().trim();
  55. varpassword=form.findField('password').getValue().trim();
  56. if(!userName){
  57. alert('用户名不能为空');
  58. return;
  59. }
  60. if(!password){
  61. alert('密码不能为空');
  62. form.submit({
  63. waitTitle:'请稍后...',255); line-height:18px"> waitMsg:'正在保存用户信息,请稍后...',92); line-height:18px"> success:function(form,action){
  64. alert(action.result.msg);
  65. failure:function(form,action){
  66. alert(action.result.msg);
  67. text:'取消',92); line-height:18px"> handler:function(){
  68. win.close();
  69. win.show();
  70. *第四种Ajax提交方式
  71. *这种方式将html的表单转化为ext的表单进行异步提交
  72. *使用这种方式,需要定义好html的表单
  73. functionsaveUser_ajaxSubmit4(){
  74. newExt.form.BasicForm('userForm').submit({
  75. }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐