rem: if(args.form){ args = _setupFromForm(args); } var ao = _setupForXhr(args); return _doIt("POST", args, ao); 
add: var dfd = _makeXhrDeferred(args); return _doIt("POST", dfd); 
context: (function(){	var _setupForXhr = function(args){		// FIXME: need to ensure that we're not performing destructive ops on		// args or pulling things out of it w/o resetting. We want users to be		// able to reuse an args obj.		// set up the query params		var qi = args.url.indexOf("?");		var miArgs = [{}];		if(qi != -1){ // url-provided params are the baseline			miArgs.push(dojo.queryToObject(args.url.substr(qi+1)));			// FIXME: destructive!!			args.url = args.url.substr(0, qi);		}		if(args.form){ // we assume that _setupFromForm has been run before us			// potentially over-ride url-provided params w/ form values			miArgs.push(dojo.queryToObject(args._formQuery));		}		if(args.content){			// stuff in content over-rides what's set by form			miArgs.push(args.content);		}		args._query = dojo.objectToQuery(dojo.mixin.apply(null, miArgs));		// .. and the real work of getting the deferred in order, etc.		var ha = args.handleAs || "text";		var _xhro = dojo._xhrObj();		var d = new dojo.Deferred(function(td){			td.canceled = true;			_xhro.abort();		});		d.addCallback(function(value){			return dojo._contentHandlers[ha](_xhro);		});		d.xhr = _xhro;		d.args = args;		d.d = d;		// FIXME: need to wire up the xhr object's abort method to something		// analagous in the Deferred		return d;	}	var _setupFromForm = function(args){		var form = dojo.byId(args.form);		args.url = args.url || form.getAttribute("action");		args._formQuery = dojo.formToQuery(form);		return args;	}	// avoid setting a timer per request. It degrades performance on IE	// something fierece if we don't use unified loops.	var _inFlightIntvl = null;	var _inFlight = [];	var _watchInFlight = function(){		//summary: 		//		internal method that checks each inflight XMLHttpRequest to see		//		if it has completed or if the timeout situation applies.		var now = (new Date()).getTime();		// make sure sync calls stay thread safe, if this callback is called		// during a sync call and this results in another sync call before the		// first sync call ends the browser hangs		if(!dojo._blockAsync){			dojo.forEach(_inFlight, function(tif, arrIdx){				try{					if(!tif || tif.d.canceled || !tif.xhr.readyState){						_inFlight.splice(arrIdx, 1); return;					}					if(4 == tif.xhr.readyState){						_inFlight.splice(arrIdx, 1); // clean refs						if(dojo._isDocumentOk(tif.xhr)){							tif.d.callback(tif.xhr);						}else{							console.debug("xhr error in:", tif.xhr);							console.debug("http response code:", tif.xhr.status);							tif.d.errback(tif.xhr);						}					}else if(tif.startTime){						//did we timeout?						if(tif.startTime + (tif.timeout) < now){							//Stop the request.							tif.d.cancel();							_inFlight.splice(arrIdx, 1); // clean refs							console.debug("xhr error in:", tif.xhr);							console.debug("timeout exceeded!");							tif.d.errback(new Error("timeout exceeded"));						}					}				}catch(e){					// FIXME: make sure we errback!					console.debug(e);					tif.d.errback(new Error("_watchInFlightError!"));				}			});		}		if(!_inFlight.length){			clearInterval(_inFlightIntvl);			_inFlightIntvl = null;			return;		}	}	var _launch = function(obj){		obj.startTime = (new Date()).getTime();		_inFlight.push(obj);		if(!_inFlightIntvl){			_inFlightIntvl = setInterval(_watchInFlight, 50);		}		_watchInFlight(); // handle sync requests	}	var _defaultContentType = "application/x-www-form-urlencoded";	var _doIt = function(type, args, ao){		// IE 6 is a steaming pile. It won't let you call apply() on the native function.		// var ga = [type, args.url, (args.sync !== true)];		// if(args.user){ ga.push(args.user, args.password); }		// ao.xhr.open.apply(ao.xhr, ga);		// workaround for IE6's apply() "issues"		ao.xhr.open(type, args.url, (args.sync !== true), (args.user ? args.user : undefined), (args.password ? args.password: undefined));		// FIXME: is this appropriate for all content types?		ao.xhr.setRequestHeader("Content-Type", (args.contentType||_defaultContentType));		// FIXME: set other headers here!		try{			ao.xhr.send(args._query);		}catch(e){			ao.d.cancel();		}		_launch(ao);		return ao.d;	}	// TODOC: FIXME!!!	dojo.xhrGet = function(/*Object*/ args){		if(args.form){ 			args = _setupFromForm(args);		}		var ao = _setupForXhr(args);		if(args._query.length){ args.url += "?"+args._query; args._query = null; }		return _doIt("GET", args, ao); // dojo.Deferred	}	dojo.xhrPost = function(/*Object*/ args){		if(args.form){ 			args = _setupFromForm(args);		}		var ao = _setupForXhr(args);		return _doIt("POST", args, ao); // dojo.Deferred	}	dojo.rawXhrPost = function(/*Object*/ args){		if(args.form){ 			args = _setupFromForm(args);		}		var ao = _setupForXhr(args);		args._query = args.postData;		return _doIt("POST", args, ao); // dojo.Deferred	}	dojo.wrapForm = function(formNode){		// was FormBind		// FIXME: waiting on connect		// FIXME: need to think harder about what extensions to this we might		// want. What should we allow folks to do w/ this? What events to		// set/send?		throw new Error("dojo.wrapForm not yet implemented");	}})();
meta: 4497	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/4497/1efca4a0c4339d77cd81880fa11173ff5ef42f29/xhr.js/clean/_base/xhr.js