Extjs form.submit()提交与Ext.Ajax.request的区别

转自:http://weizhilizhiwei.iteye.com/blog/1671431

 之前总是封不起Extjs中form.submit()提交与Ext.Ajax.request()的区别,现在仍是分不清,但是知道怎么用不会出错了。

方案1:

java action中的代码

 

Java代码   收藏代码
  1. String datastring = "total : " + rehpage.getCount() + ", root : [";  
  2. if (rehpage != null) {  
  3.     datastring += buildJsonByPage(rehpage);  
  4. }  
  5. datastring = datastring + "]";  
  6. StringBuffer buff = new StringBuffer("{success:true,mes:{");  
  7. buff.append(datastring);  
  8. buff.append("}}");  
  9.   
  10. System.out.println("datastring is: " + buff.toString());  
  11. request.setAttribute("responseText", buff.toString().replaceAll("\r\n",  
  12.         " ").replaceAll("\n"" "));// 将拼接好的数据放到request  
  13. return SUCCESS;  

 对用的Extjs中的代码为:

 

Java代码   收藏代码
  1.     Ext.Ajax.request({  
  2.                 url : "./rehearsal/queryTableData.action",  
  3.                 params : {  
  4.                     search_place : rehearsal_place,  
  5.                     search_time : dt  
  6.                             .format('Y-m-d'),  
  7.                     search_valuation : null,  
  8.                     search_subject : search_subject  
  9.                 },  
  10.                 waitMsg : '正在提交数据',  
  11.                 waitTitle : '提示',  
  12.                 method : "POST",  
  13.                 success : function(response) {  
  14.                     var respText = Ext.util.JSON  
  15.                             .decode(response.responseText);  
  16.                     if (respText.success) {  
  17.                         szcdc_rehearsal_one_grid  
  18.                                 .getStore()  
  19.                                 .loadData(respText.mes);  
  20.                     }  
  21.                 },  
  22.                 failure : function(response) {  
  23.                     Ext.Msg.alert('提示',  
  24.                             "操作失败:输入非法字符!!!");  
  25.                 }  
  26.             });  
  27. }  

 方案2:

java action中的代码是:

 

 

Java代码   收藏代码
  1. String datastring = "total : " + rehpage.getCount() + ", root : [";  
  2. if (rehpage != null) {  
  3.     datastring += buildJsonByPage(rehpage);  
  4. }  
  5. datastring = datastring + "]";  
  6. StringBuffer buff = new StringBuffer("{success:true,");  
  7. buff.append(datastring);  
  8. buff.append("}");  
  9.   
  10. System.out.println("datastring is: " + buff.toString());  
  11. request.setAttribute("responseText", buff.toString().replaceAll("\r\n",  
  12.         " ").replaceAll("\n"" "));// 将拼接好的数据放到request  
  13. return SUCCESS;  

 对应的Extjs代码为:

 

Java代码   收藏代码
  1. search_form.submit({  
  2.     url : "./rehearsal/queryTableData.action",  
  3.     baseParams : {  
  4.         search_place : rehearsal_place,  
  5.         search_time : search_time,  
  6.         search_valuation : search_valuation,  
  7.         search_subject : search_subject  
  8.     },  
  9.     waitMsg : '正在提交数据',  
  10.     waitTitle : '提示',  
  11.     method : "POST",  
  12.     success : function(form, action) {  
  13.         // 得到数据  
  14.         var result = Ext.util.JSON  
  15.                 .decode(action.response.responseText);// 就可以取出来。如果是数组,那么很简单  
  16.         // 把数据放到结果里面  
  17.         szcdc_rehearsal_one_grid.getStore()  
  18.                 .loadData(result);  
  19.     },  
  20.     failure : function(form, action) {  
  21.         Ext.Msg.alert('提示'"操作失败:输入非法字符!!!");  
  22.     }  
  23. });  


将form中的字段转成json格式:form.getForm().getFieldValues();


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值