add:      var ld = args.load; if(ld && dojo.isFunction(ld)){ d.addCallback(function(value){ return ld.call(args, value, ioArgs); }); } var err = args.error; if(err && dojo.isFunction(err)){ d.addErrback(function(value){ return err.call(args, value, ioArgs); }); } var handle = args.handle; if(handle && dojo.isFunction(handle)){ d.addBoth(function(value){ return handle.call(args, value, ioArgs); }); }  d.ioArgs = ioArgs;    return d;  }  var _deferredCancel = function(/*Deferred*/dfd){   dfd.canceled = true; var xhr = dfd.ioArgs.xhr; if(typeof xhr.abort == "function"){ xhr.abort(); } } var _deferredOk = function(/*Deferred*/dfd){   return dojo._contentHandlers[dfd.ioArgs.handleAs](dfd.ioArgs.xhr); } var _deferError = function(/*Error*/error, /*Deferred*/dfd){    console.debug(error); return error; }  var _makeXhrDeferred = function(/*Object*/args){  var dfd = dojo._ioSetArgs(args, _deferredCancel, _deferredOk, _deferError); dfd.ioArgs.xhr = dojo._xhrObj(); return dfd; }    var _inFlightIntvl = null; var _inFlight = []; var _watchInFlight = function(){     var now = (new Date()).getTime();    if(!dojo._blockAsync){ dojo.forEach(_inFlight, function(tif, arrIdx){ if(!tif){ return; } var dfd = tif.dfd; try{ if(!dfd || dfd.canceled || !tif.validCheck(dfd)){ _inFlight.splice(arrIdx, 1); return; } if(tif.ioCheck(dfd)){ _inFlight.splice(arrIdx, 1); tif.resHandle(dfd); }else if(dfd.startTime){  if(dfd.startTime + (dfd.ioArgs.args.timeout||0) < now){ _inFlight.splice(arrIdx, 1); var err = new Error("timeout exceeded"); err.dojoType = "timeout"; dfd.errback(err);  dfd.cancel(); } } }catch(e){  console.debug(e); dfd.errback(new Error("_watchInFlightError!")); } }); }  if(!_inFlight.length){ clearInterval(_inFlightIntvl); _inFlightIntvl = null; return; }   }  dojo._ioWatch = function(/*Deferred*/dfd, /*Function*/validCheck, /*Function*/ioCheck, /*Function*/resHandle){             if(dfd.ioArgs.args.timeout){ dfd.startTime = (new Date()).getTime(); } _inFlight.push({dfd: dfd, validCheck: validCheck, ioCheck: ioCheck, resHandle: resHandle}); if(!_inFlightIntvl){ _inFlightIntvl = setInterval(_watchInFlight, 50); } _watchInFlight(); }  var _defaultContentType = "application/x-www-form-urlencoded";  var _validCheck = function(/*Deferred*/dfd){ return dfd.ioArgs.xhr.readyState; } var _ioCheck = function(/*Deferred*/dfd){ return 4 == dfd.ioArgs.xhr.readyState; } var _resHandle = function(/*Deferred*/dfd){ if(dojo._isDocumentOk(dfd.ioArgs.xhr)){ dfd.callback(dfd); }else{ dfd.errback(new Error("bad http response code:" + dfd.ioArgs.xhr.status)); } }  var _doIt = function(/*String*/type, /*Deferred*/dfd){   var ioArgs = dfd.ioArgs; var args = ioArgs.args; ioArgs.xhr.open(type, ioArgs.url, (args.sync !== true), (args.user ? args.user : undefined), (args.password ? args.password: undefined)); if(args.headers){ for(var hdr in args.headers){ if(hdr.toLowerCase() === "content-type" && !args.contentType){ args.contentType = args.headers[hdr]; }else{ ioArgs.xhr.setRequestHeader(hdr, args.headers[hdr]); } } }  ioArgs.xhr.setRequestHeader("Content-Type", (args.contentType||_defaultContentType));  try{ ioArgs.xhr.send(ioArgs.query); }catch(e){ dfd.cancel(); } dojo._ioWatch(dfd, _validCheck, _ioCheck, _resHandle); return dfd; }  dojo._ioAddQueryToUrl = function(/*Object*/ioArgs){   if(ioArgs.query.length){ ioArgs.url += (ioArgs.url.indexOf("?") == -1 ? "?" : "&") + ioArgs.query; ioArgs.query = null; } }    dojo.xhrGet = function(/*Object*/ args){          var dfd = _makeXhrDeferred(args); dojo._ioAddQueryToUrl(dfd.ioArgs); return _doIt("GET", dfd); }  dojo.xhrPost = function(/*Object*/ args){   return _doIt("POST", _makeXhrDeferred(args)); }  dojo.rawXhrPost = function(/*Object*/ args){      var dfd = _makeXhrDeferred(args); dfd.ioArgs.query = args.postData; return _doIt("POST", dfd); }  dojo.xhrPut = function(/*Object*/ args){   return _doIt("PUT", _makeXhrDeferred(args)); }  dojo.rawXhrPut = function(/*Object*/ args){      var dfd = _makeXhrDeferred(args); var ioArgs = dfd.ioArgs; if(args["putData"]){ ioArgs.query = args.putData; args.putData = null; } return _doIt("PUT", dfd); }  dojo.xhrDelete = function(/*Object*/ args){   var dfd = _makeXhrDeferred(args); dojo._ioAddQueryToUrl(dfd.ioArgs); return _doIt("DELETE", dfd); }  dojo.wrapForm = function(formNode){      throw new Error("dojo.wrapForm not yet implemented"); } })(); 
context: 		d.addCallbacks(okHandler, function(error){				return errHandler(error, d);		});
meta: 4497	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/4497/99b898ca92c804bf3c4cef2456c343ef8f881675/xhr.js/buggy/_base/xhr.js