加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Extjs用ajax提交表单四种方式

发布时间:2020-12-15 22:08:43 所属栏目:百科 来源:网络整理
导读:/** *p *第一种Ajax提交方式 */p *p *这种方式需要直接使用extAjax方法进行提交 */p *使用这种方式,需要将待传递的参数进行封装 * *@return */ functionsaveUser_ajaxSubmit1(){ Ext.Ajax.request({ url: 'user_save.action' , method: 'post' , params:{ u
  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. fieldLabel:'密码',92); line-height:18px"> name:'password'
  47. }]
  48. //定义窗口
  49. varwin=newExt.Window({
  50. 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:[{
  51. text:'确定',255); line-height:18px"> handler:function(){
  52. varform=formPanel.getForm();
  53. varuserName=form.findField('userName').getValue().trim();
  54. varpassword=form.findField('password').getValue().trim();
  55. if(!userName){
  56. alert('用户名不能为空');
  57. return;
  58. }
  59. if(!password){
  60. alert('密码不能为空');
  61. form.submit({
  62. waitTitle:'请稍后...',255); line-height:18px"> waitMsg:'正在保存用户信息,请稍后...',92); line-height:18px"> success:function(form,action){
  63. alert(action.result.msg);
  64. failure:function(form,action){
  65. alert(action.result.msg);
  66. text:'取消',92); line-height:18px"> handler:function(){
  67. win.close();
  68. win.show();
  69. *第四种Ajax提交方式
  70. *这种方式将html的表单转化为ext的表单进行异步提交
  71. *使用这种方式,需要定义好html的表单
  72. functionsaveUser_ajaxSubmit4(){
  73. newExt.form.BasicForm('userForm').submit({
  74. }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读