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

 Ext.Ajax.request({  

  •                 url : "./rehearsal/queryTableData.action",  
  •                 params : {  
  •                     search_place : rehearsal_place,  
  •                     search_time : dt  
  •                             .format('Y-m-d'),  
  •                     search_valuation : null,  
  •                     search_subject : search_subject  
  •                 },  
  •                 waitMsg : '正在提交数据',  
  •                 waitTitle : '提示',  
  •                 method : "POST",  
  •                 success : function(response) {  
  •                     var respText = Ext.util.JSON  
  •                             .decode(response.responseText);  
  •                     if (respText.success) {  
  •                         szcdc_rehearsal_one_grid  
  •                                 .getStore()  
  •                                 .loadData(respText.mes);  
  •                     }  
  •                 },  
  •                 failure : function(response) {  
  •                     Ext.Msg.alert('提示',  
  •                             "操作失败:输入非法字符!!!");  
  •                 }  
  •             });  
  • }  
  • 对应的JAVA后台代码:
  • String datastring = "total : " + rehpage.getCount() + ", root : [";  
    • if (rehpage != null) {  
    •     datastring += buildJsonByPage(rehpage);  
    • }  
    • datastring = datastring + "]";  
    • StringBuffer buff = new StringBuffer("{success:true,mes:{");  
    • buff.append(datastring);  
    • buff.append("}}");  
    •   
    • System.out.println("datastring is: " + buff.toString());  
    • request.setAttribute("responseText", buff.toString().replaceAll("\r\n",  
    •         " ").replaceAll("\n", " "));// 将拼接好的数据放到request  
    • return SUCCESS;  
  • 第二种提交方式:
  • search_form.submit({  
    •     url : "./rehearsal/queryTableData.action",  
    •     baseParams : {  
    •         search_place : rehearsal_place,  
    •         search_time : search_time,  
    •         search_valuation : search_valuation,  
    •         search_subject : search_subject  
    •     },  
    •     waitMsg : '正在提交数据',  
    •     waitTitle : '提示',  
    •     method : "POST",  
    •     success : function(form, action) {  
    •         // 得到数据  
    •         var result = Ext.util.JSON  
    •                 .decode(action.response.responseText);// 就可以取出来。如果是数组,那么很简单  
    •         // 把数据放到结果里面  
    •         szcdc_rehearsal_one_grid.getStore()  
    •                 .loadData(result);  
    •     },  
    •     failure : function(form, action) {  
    •         Ext.Msg.alert('提示', "操作失败:输入非法字符!!!");  
    •     }  
    • });  
    • 对应的后台处理方式是:
    • String datastring = "total : " + rehpage.getCount() + ", root : [";  
      • if (rehpage != null) {  
      •     datastring += buildJsonByPage(rehpage);  
      • }  
      • datastring = datastring + "]";  
      • StringBuffer buff = new StringBuffer("{success:true,");  
      • buff.append(datastring);  
      • buff.append("}");  
      •   
      • System.out.println("datastring is: " + buff.toString());  
      • request.setAttribute("responseText", buff.toString().replaceAll("\r\n",  
      •         " ").replaceAll("\n", " "));// 将拼接好的数据放到request  
      • return SUCCESS;  
posted @ 2014-11-05 12:04  silence2010  阅读(132)  评论(0)    收藏  举报