All pastes #960012 Raw Edit

Anonymous

public javascript v1 · immutable
#960012 ·published 2008-03-27 20:44 UTC
rendered paste body
function AsyncRequest(div, url, options){	this.div = '';	this.options = 	{		data: '',		method: 'POST'	};	this.initialize = function(div, url, options) 	{		this.div = div;		if (options.method)		{			if (options.method == "GET")			{				this.options.method = "GET";			}		}				if (options.formId)		{			this.options.data = YAHOO.util.Connect.setForm(options.formId);		}		if (options.data)		{			this.options.data = options.data;		}		alert("firing request using " + this.options.method + " to " + url + " with " + this.options.data);		YAHOO.util.Connect.asyncRequest(this.options.method, url, this.callback, this.options.data);	};	this.evalJS = function(html)	{		var re = new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'igm'); // assumes HTML well formed		var match;		while (match = re.exec(html))		{			eval(match[1]);		}	};	this.handleSuccess = function(o)	{		if (o.responseText != null && this.div != '')		{						var div = document.getElementById(this.div);			var source = o.responseText;			this.evalJS(source);			div.innerHTML = source;		}	};	this.handleFailure = function(o)	{			};	this.callback = 	{		success: this.handleSuccess,		failure: this.handleFailure	};	this.initialize(div, url, options);};