⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ajaxstruts.js

📁 ajax for java to get server
💻 JS
字号:
/**Author:guosg*ajaxStruts1.0****/Ajax.struts = function(){};Ajax.struts.form = function(){};Ajax.struts.form.prototype = {	initialize: function() {			},	input:function(obj,data){		if(obj.type.toLowerCase()=="checkbox"){								if(data.toLowerCase()=="true" || data==obj.value){				obj.checked=true;			}else {				obj.checked=false;			}					}else if(obj.type.toLowerCase()=="radio"){						obj.each(function(subObj){						if(subObj.value==data){							subObj.checked=true;						}					}			);					}else{			obj.value = data;		}	},	form:function(obj,data){		alert("form");		var formData = data["0"];		for(property in formData){			var curObj = $(property);			var curData = formData[property];			alert(property);			if(curObj){				if(curObj.tagName.toLowerCase()=="input"){					var formF = new Ajax.struts.form();					formF.input(curObj,curData);				}else{					curObj.value = curData;				}			}		}	},		selectOption:function(obj,data){		var i=0;		for(property in data){			//alert(data[i].value);			var curObj = data[i];			var oOption = document.createElement("OPTION");			oOption.text=curObj.label;			oOption.value=curObj.value;			obj.add(oOption);			i++;		}	},		select:function(obj,data){		//alert("select");		if(typeof(data)=="object"){			//for(var i=0;i<data.property.length)			var formF = new Ajax.struts.form();			formF.selectOption(obj,data);		}else{			obj.value = data;		}	}}Ajax.struts.user =  function(){};Ajax.struts.user.prototype = {	initialize: function() {			}}Ajax.struts.clazz = function(){};Ajax.struts.clazz.prototype = {	initialize: function() {			},		grid:function(){			document.write("<br>---------------grid---------------<br>")			document.write("grid=" + this.curData[0]["item1"]+"<br>");	}}Ajax.struts.base = new Class.create();Ajax.struts.base.prototype = {	initialize: function(url,form) {		this.curData=null;		this.curObj=null;		this.serverObj = "";		this.url = url;		this.method="post";		this.asynchronous=true;		this.parameters={};		this.form=form;		this.formCfg = {};		this.clazzCfg = {};		this.userCfg = {};				this.abc = this._switchF;				var formF = new Ajax.struts.form();		var clazz = new Ajax.struts.clazz();		this.setFormCfg("INPUT",formF.input);		this.setFormCfg("FORM",formF.form);		this.setFormCfg("SELECT",formF.select);		this.setClazzCfg("grid",clazz.grid);	},	setFormCfg:function(str,obj){		this.formCfg[str] = obj;	},	setClazzCfg:function(str,obj){		this.clazzCfg[str] = obj;	},	setUserCfg:function(str,obj){		this.userCfg[str] =obj;	},	setParam:function(name,value){		this.parameters[name] = value;	}	}Ajax.struts.process = new Class.create();Ajax.struts.process.prototype = Object.extend(new Ajax.struts.base(),{				submit:function(){			var dt = new Date();			var sParam = $H(this.parameters).toQueryString() +"&"+ dt.getTime();			alert(sParam);			var myAjax = new Ajax.Request(				this.url,				{	method: this.method, 					parameters: sParam, 					onComplete: this.showResponse.bind(this),					postBody:Form.serialize(this.form)+"&"+sParam				}			);		},		showResponse:function(req,obj){			//alert(req.responseText);			this.serverObj = eval(req.responseText);			//this.serverObj = eval(req);			//ert(this.serverObj.name);						this._switchF();		},		viewProperty:function(){			document.write("<br>-----------------<br>");			for(property in this){				document.write(property+"<br>");				//$(x).value = property;			}				document.write("<br>-----------------<br>");				//this.userCfg.each(function(value){document.write(value+"<br>")});				document.write("<br>-----------------<br>");				document.write("url="+this.url);		},		_switchF:function(){			//alert("_switchF");			for(property in this.serverObj){				//document.write(property+"<br>");				//document.write(property+"="+this.serverObj[property].name+"<br>");				var oName = property;				var curObj = $(oName);				var curData = this.serverObj[property];				//document.write(curData.name+"<br>");				if(curObj){					if(this.formCfg[curObj.tagName.toUpperCase()])						this.formCfg[curObj.tagName.toUpperCase()].apply(this,[curObj,curData]);												var fun = this.clazzCfg;						var curFun = null;												Element.classNames(curObj).each(														 	function (value){																if(fun[value]){																	curFun = fun[value];																}															}														);					if(curFun!=null) curFun.apply(this,[curObj,curData]);				}								if(this.userCfg[property]){						this.userCfg[property].apply(this,[curObj,curData]);				}			}		}	})

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -