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

📄 browserio.js

📁 dojo与json创建无限级树的时候,当在父结点下添加了一个新结点,我怎么让父亲结点重新调用json加载一下子结点内容.
💻 JS
📖 第 1 页 / 共 2 页
字号:
			kwArgs[(typeof kwArgs.error == "function") ? "error" : "handle"]("error", errObj, http, kwArgs);		}	}	// set headers (note: Content-Type will get overriden if kwArgs.contentType is set)	function setHeaders(http, kwArgs){		if(kwArgs["headers"]) {			for(var header in kwArgs["headers"]) {				if(header.toLowerCase() == "content-type" && !kwArgs["contentType"]) {					kwArgs["contentType"] = kwArgs["headers"][header];				} else {					http.setRequestHeader(header, kwArgs["headers"][header]);				}			}		}	}	this.inFlight = [];	this.inFlightTimer = null;	this.startWatchingInFlight = function(){		if(!this.inFlightTimer){			this.inFlightTimer = setInterval("dojo.io.XMLHTTPTransport.watchInFlight();", 10);		}	}	this.watchInFlight = function(){		var now = null;		for(var x=this.inFlight.length-1; x>=0; x--){			var tif = this.inFlight[x];			if(!tif){ this.inFlight.splice(x, 1); continue; }			if(4==tif.http.readyState){				// remove it so we can clean refs				this.inFlight.splice(x, 1);				doLoad(tif.req, tif.http, tif.url, tif.query, tif.useCache);			}else if (tif.startTime){				//See if this is a timeout case.				if(!now){					now = (new Date()).getTime();				}				if(tif.startTime + (tif.req.timeoutSeconds * 1000) < now){					//Stop the request.					if(typeof tif.http.abort == "function"){						tif.http.abort();					}					// remove it so we can clean refs					this.inFlight.splice(x, 1);					tif.req[(typeof tif.req.timeout == "function") ? "timeout" : "handle"]("timeout", null, tif.http, tif.req);				}			}		}		if(this.inFlight.length == 0){			clearInterval(this.inFlightTimer);			this.inFlightTimer = null;		}	}	var hasXmlHttp = dojo.hostenv.getXmlhttpObject() ? true : false;	this.canHandle = function(kwArgs){		// canHandle just tells dojo.io.bind() if this is a good transport to		// use for the particular type of request.		// FIXME: we need to determine when form values need to be		// multi-part mime encoded and avoid using this transport for those		// requests.		return hasXmlHttp			&& dojo.lang.inArray((kwArgs["mimetype"].toLowerCase()||""), ["text/plain", "text/html", "application/xml", "text/xml", "text/javascript", "text/json"])			&& !( kwArgs["formNode"] && dojo.io.formHasFile(kwArgs["formNode"]) );	}	this.multipartBoundary = "45309FFF-BD65-4d50-99C9-36986896A96F";	// unique guid as a boundary value for multipart posts	this.bind = function(kwArgs){		if(!kwArgs["url"]){			// are we performing a history action?			if( !kwArgs["formNode"]				&& (kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"] || kwArgs["watchForURL"])				&& (!djConfig.preventBackButtonFix)) {        dojo.deprecated("Using dojo.io.XMLHTTPTransport.bind() to add to browser history without doing an IO request",        				"Use dojo.undo.browser.addToHistory() instead.", "0.4");				dojo.undo.browser.addToHistory(kwArgs);				return true;			}		}		// build this first for cache purposes		var url = kwArgs.url;		var query = "";		if(kwArgs["formNode"]){			var ta = kwArgs.formNode.getAttribute("action");			if((ta)&&(!kwArgs["url"])){ url = ta; }			var tp = kwArgs.formNode.getAttribute("method");			if((tp)&&(!kwArgs["method"])){ kwArgs.method = tp; }			query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding, kwArgs["formFilter"]);		}		if(url.indexOf("#") > -1) {			dojo.debug("Warning: dojo.io.bind: stripping hash values from url:", url);			url = url.split("#")[0];		}		if(kwArgs["file"]){			// force post for file transfer			kwArgs.method = "post";		}		if(!kwArgs["method"]){			kwArgs.method = "get";		}		// guess the multipart value				if(kwArgs.method.toLowerCase() == "get"){			// GET cannot use multipart			kwArgs.multipart = false;		}else{			if(kwArgs["file"]){				// enforce multipart when sending files				kwArgs.multipart = true;			}else if(!kwArgs["multipart"]){				// default 				kwArgs.multipart = false;			}		}		if(kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"]){			dojo.undo.browser.addToHistory(kwArgs);		}		var content = kwArgs["content"] || {};		if(kwArgs.sendTransport) {			content["dojo.transport"] = "xmlhttp";		}		do { // break-block			if(kwArgs.postContent){				query = kwArgs.postContent;				break;			}			if(content) {				query += dojo.io.argsFromMap(content, kwArgs.encoding);			}						if(kwArgs.method.toLowerCase() == "get" || !kwArgs.multipart){				break;			}			var	t = [];			if(query.length){				var q = query.split("&");				for(var i = 0; i < q.length; ++i){					if(q[i].length){						var p = q[i].split("=");						t.push(	"--" + this.multipartBoundary,								"Content-Disposition: form-data; name=\"" + p[0] + "\"", 								"",								p[1]);					}				}			}			if(kwArgs.file){				if(dojo.lang.isArray(kwArgs.file)){					for(var i = 0; i < kwArgs.file.length; ++i){						var o = kwArgs.file[i];						t.push(	"--" + this.multipartBoundary,								"Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",								"Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),								"",								o.content);					}				}else{					var o = kwArgs.file;					t.push(	"--" + this.multipartBoundary,							"Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",							"Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),							"",							o.content);				}			}			if(t.length){				t.push("--"+this.multipartBoundary+"--", "");				query = t.join("\r\n");			}		}while(false);		// kwArgs.Connection = "close";		var async = kwArgs["sync"] ? false : true;		var preventCache = kwArgs["preventCache"] ||			(this.preventCache == true && kwArgs["preventCache"] != false);		var useCache = kwArgs["useCache"] == true ||			(this.useCache == true && kwArgs["useCache"] != false );		// preventCache is browser-level (add query string junk), useCache		// is for the local cache. If we say preventCache, then don't attempt		// to look in the cache, but if useCache is true, we still want to cache		// the response		if(!preventCache && useCache){			var cachedHttp = getFromCache(url, query, kwArgs.method);			if(cachedHttp){				doLoad(kwArgs, cachedHttp, url, query, false);				return;			}		}		// much of this is from getText, but reproduced here because we need		// more flexibility		var http = dojo.hostenv.getXmlhttpObject(kwArgs);			var received = false;		// build a handler function that calls back to the handler obj		if(async){			var startTime = 			// FIXME: setting up this callback handler leaks on IE!!!			this.inFlight.push({				"req":		kwArgs,				"http":		http,				"url":	 	url,				"query":	query,				"useCache":	useCache,				"startTime": kwArgs.timeoutSeconds ? (new Date()).getTime() : 0			});			this.startWatchingInFlight();		}		if(kwArgs.method.toLowerCase() == "post"){			// FIXME: need to hack in more flexible Content-Type setting here!			http.open("POST", url, async);			setHeaders(http, kwArgs);			http.setRequestHeader("Content-Type", kwArgs.multipart ? ("multipart/form-data; boundary=" + this.multipartBoundary) : 				(kwArgs.contentType || "application/x-www-form-urlencoded"));			try{				http.send(query);			}catch(e){				if(typeof http.abort == "function"){					http.abort();				}				doLoad(kwArgs, {status: 404}, url, query, useCache);			}		}else{			var tmpUrl = url;			if(query != "") {				tmpUrl += (tmpUrl.indexOf("?") > -1 ? "&" : "?") + query;			}			if(preventCache) {				tmpUrl += (dojo.string.endsWithAny(tmpUrl, "?", "&")					? "" : (tmpUrl.indexOf("?") > -1 ? "&" : "?")) + "dojo.preventCache=" + new Date().valueOf();			}			http.open(kwArgs.method.toUpperCase(), tmpUrl, async);			setHeaders(http, kwArgs);			try {				http.send(null);			}catch(e)	{				if(typeof http.abort == "function"){					http.abort();				}				doLoad(kwArgs, {status: 404}, url, query, useCache);			}		}		if( !async ) {			doLoad(kwArgs, http, url, query, useCache);		}		kwArgs.abort = function(){			return http.abort();		}		return;	}	dojo.io.transports.addTransport("XMLHTTPTransport");}

⌨️ 快捷键说明

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