为Ext.form.Action.Submit增加JSON/xml数据发送

这两日搞了一下Ext3,发现Ext.form.FormPanel居然不能发送JSON/xml数据到服务端,不知道是不是我没有找到方法,郁闷了一天。
最简单的办法就是,直接重写Ext.form.Action.Submit.run
在request参数中配置有
jsonData或者xmlData就可以将json或者xml发送到服务端了
Ext.override(Ext.form.Action.Submit,{
	run:function(){	
		 var o = this.options,
	     method = this.getMethod(),
	     isGet = method == 'GET';
		 if(o.clientValidation === false || this.form.isValid()){
		     if (o.submitEmptyText === false) {
		         var fields = this.form.items,
		             emptyFields = [];
		         fields.each(function(f) {
		             if (f.el.getValue() == f.emptyText) {
		                 emptyFields.push(f);
		                 f.el.dom.value = "";
		             }
		         });
		     }
		     
		     if(o.jsonData){
			     Ext.Ajax.request(Ext.apply(this.createCallback(o), {		         
			         url:this.getUrl(isGet),
			         method: method,
			         headers: o.headers,
			         jsonData:o.jsonData
			     }));	    	 
		     }else if(o.xmlData){
			     Ext.Ajax.request(Ext.apply(this.createCallback(o), {		         
			         url:this.getUrl(isGet),
			         method: method,
			         headers: o.headers,
			         xmlData:o.xmlData
			     }));	    	 
		     }else{
			     Ext.Ajax.request(Ext.apply(this.createCallback(o), {
			         form:this.form.el.dom,
			         url:this.getUrl(isGet),
			         method: method,
			         headers: o.headers,
			         params:!isGet ? this.getParams() : null,
			         isUpload: this.form.fileUpload
			     }));	    	 
		     }
	
		     if (o.submitEmptyText === false) {
		         Ext.each(emptyFields, function(f) {
		             if (f.applyEmptyText) {
		                 f.applyEmptyText();
		             }
		         });
		     }
		 }else if (o.clientValidation !== false){ // client validation failed
		     this.failureType = Ext.form.Action.CLIENT_INVALID;
		     this.form.afterAction(this, false);
		 }
	}  return Ext.decode(response.responseText);
    }
});

你可能感兴趣的:(xml,json,Ajax,ext,F#)