Extjs FormPanel提交与普通Ajax提交的区别

项目中一次用到EXTJS的FORMPANEL的提交方式,本以为会与普通AJAX提交方式相同,但是,后来发现两者之间有一些区别,记录如下:
前端EXTJS FORMPANEL代码如下:
buttons: [{
                text:'提交',
                handler: 
function (){
                    
if (dyt_editForm.form.isValid()){
                        dyt_editForm.form.submit({
                            url: '
/ tams / xxcj / modifySssq',  // 处理修改后台地址
                            method: 'post',
                            params: {daid: v.get(
" da_id " )},
                            success: 
function  (f,v){
                                
var  myResult  =  Ext.util.JSON.decode(v.response.responseText);    //这句代码与普通解析返回字符串不一样
                                alert(myResult.result);
                            },
                            failure: 
function  (f,v){
                                Ext.MessageBox.show({
                                    title: '失败',
                                    msg: '修改出现异常,未能完成,请重试!',
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.ERROR
                                });
                            },
                            waitMsg: '正在处理数据,请稍后……',
                            scope: 
this
                        });
                    }
                }
            },{
                  text: '取消',
                  handler: 
function (){
                      dyt_editwin.close();
                  }
              }]
后台可以直接按照普通网页的方式,按照FORM内控件的名称获取各自的值,后台代码如下:
/**
     *    修改所属时期起止时间 
     
*/
    
public   void  modifySssq(HttpServletRequest request,
            HttpServletResponse response) {
        System.out.println(
" ************* " );
        String daid 
=  request.getParameter( " daid " );
        Date date1 
=  Date.valueOf(request.getParameter( " sssqq " ));
        Date date2 
=  Date.valueOf(request.getParameter( " sssqz " ));
        String results 
=  DAOFactory.getXxcjDAO().modifySssq(Long.parseLong(daid), date1, date2);
        
        
if ( " success " .equals(results)){
            results 
=   " 修改所属税务时期操作成功! " ;
        }
else {
            results 
=   " 修改所属税务时期操作失败! " ;
        }
        
try  {
            //返回值需要封装一下
            Map jsonmap 
=   new  HashMap();
            //这里是想要返回前台的值
            jsonmap.put(
" result " , results);   
            //区别就在这里了,必须要传回去一个“success”,前台才能判断请求是否成功                          
            jsonmap.put(
" success " new  Boolean( true ));
            JSONObject jsonObject 
=  JSONObject.fromObject(jsonmap);
            response.setContentType(
" text/json; charset=utf-8 " );
            response.getWriter().print(jsonObject);
        } 
catch  (IOException e) {
            log.error(
" 输出返回值失败: "   +  e.getMessage());
        }
    }
(完)


你可能感兴趣的:(Extjs FormPanel提交与普通Ajax提交的区别)