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

📄 xhr.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
if(!dojo._hasResource["dojo._base.xhr"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojo._base.xhr"] = true;dojo.provide("dojo._base.xhr");dojo.require("dojo._base.Deferred");dojo.require("dojo._base.json");dojo.require("dojo._base.lang");dojo.require("dojo._base.query");(function(){	var _d = dojo;	function setValue(/*Object*/obj, /*String*/name, /*String*/value){		//summary:		//		For the nameed property in object, set the value. If a value		//		already exists and it is a string, convert the value to be an		//		array of values.		var val = obj[name];		if(_d.isString(val)){			obj[name] = [val, value];		}else if(_d.isArray(val)){			val.push(value);		}else{			obj[name] = value;		}	}	dojo.formToObject = function(/*DOMNode||String*/ formNode){		// summary:		//		dojo.formToObject returns the values encoded in an HTML form as		//		string properties in an object which it then returns. Disabled form		//		elements, buttons, and other non-value form elements are skipped.		//		Multi-select elements are returned as an array of string values.		// description:		//		This form:		//		//		|	<form id="test_form">		//		|		<input type="text" name="blah" value="blah">		//		|		<input type="text" name="no_value" value="blah" disabled>		//		|		<input type="button" name="no_value2" value="blah">		//		|		<select type="select" multiple name="multi" size="5">		//		|			<option value="blah">blah</option>		//		|			<option value="thud" selected>thud</option>		//		|			<option value="thonk" selected>thonk</option>		//		|		</select>		//		|	</form>		//		//		yields this object structure as the result of a call to		//		formToObject():		//		//		|	{ 		//		|		blah: "blah",		//		|		multi: [		//		|			"thud",		//		|			"thonk"		//		|		]		//		|	};			var ret = {};		var iq = "input:not([type=file]):not([type=submit]):not([type=image]):not([type=reset]):not([type=button]), select, textarea";		_d.query(iq, formNode).filter(function(node){			return !node.disabled && node.name;		}).forEach(function(item){			var _in = item.name;			var type = (item.type||"").toLowerCase();			if(type == "radio" || type == "checkbox"){				if(item.checked){ setValue(ret, _in, item.value); }			}else if(item.multiple){				ret[_in] = [];				_d.query("option", item).forEach(function(opt){					if(opt.selected){						setValue(ret, _in, opt.value);					}				});			}else{ 				setValue(ret, _in, item.value);				if(type == "image"){					ret[_in+".x"] = ret[_in+".y"] = ret[_in].x = ret[_in].y = 0;				}			}		});		return ret; // Object	}	dojo.objectToQuery = function(/*Object*/ map){		//	summary:		//		takes a name/value mapping object and returns a string representing		//		a URL-encoded version of that object.		//	example:		//		this object:		//		//		|	{ 		//		|		blah: "blah",		//		|		multi: [		//		|			"thud",		//		|			"thonk"		//		|		]		//		|	};		//		//	yields the following query string:		//			//	|	"blah=blah&multi=thud&multi=thonk"		// FIXME: need to implement encodeAscii!!		var enc = encodeURIComponent;		var pairs = [];		var backstop = {};		for(var name in map){			var value = map[name];			if(value != backstop[name]){				var assign = enc(name) + "=";				if(_d.isArray(value)){					for(var i=0; i < value.length; i++){						pairs.push(assign + enc(value[i]));					}				}else{					pairs.push(assign + enc(value));				}			}		}		return pairs.join("&"); // String	}	dojo.formToQuery = function(/*DOMNode||String*/ formNode){		// summary:		//		Returns a URL-encoded string representing the form passed as either a		//		node or string ID identifying the form to serialize		return _d.objectToQuery(_d.formToObject(formNode)); // String	}	dojo.formToJson = function(/*DOMNode||String*/ formNode, /*Boolean?*/prettyPrint){		// summary:		//		return a serialized JSON string from a form node or string		//		ID identifying the form to serialize		return _d.toJson(_d.formToObject(formNode), prettyPrint); // String	}	dojo.queryToObject = function(/*String*/ str){		// summary:		//		returns an object representing a de-serialized query section of a		//		URL. Query keys with multiple values are returned in an array.		// description:		//		This string:		//		//	|		"foo=bar&foo=baz&thinger=%20spaces%20=blah&zonk=blarg&"		//				//		results in this object structure:		//		//	|		{		//	|			foo: [ "bar", "baz" ],		//	|			thinger: " spaces =blah",		//	|			zonk: "blarg"		//	|		}		//			//		Note that spaces and other urlencoded entities are correctly		//		handled.		// FIXME: should we grab the URL string if we're not passed one?		var ret = {};		var qp = str.split("&");		var dec = decodeURIComponent;		_d.forEach(qp, function(item){			if(item.length){				var parts = item.split("=");				var name = dec(parts.shift());				var val = dec(parts.join("="));				if(_d.isString(ret[name])){					ret[name] = [ret[name]];				}				if(_d.isArray(ret[name])){					ret[name].push(val);				}else{					ret[name] = val;				}			}		});		return ret; // Object	}	/*		from refactor.txt:		all bind() replacement APIs take the following argument structure:			{				url: "blah.html",				// all below are optional, but must be supported in some form by				// every IO API				timeout: 1000, // milliseconds				handleAs: "text", // replaces the always-wrong "mimetype"				content: { 					key: "value"				},				// browser-specific, MAY be unsupported				sync: true, // defaults to false				form: dojo.byId("someForm") 			}	*/	// need to block async callbacks from snatching this thread as the result	// of an async callback might call another sync XHR, this hangs khtml forever	// must checked by watchInFlight()	dojo._blockAsync = false;	dojo._contentHandlers = {		"text": function(xhr){ return xhr.responseText; },		"json": function(xhr){			if(!dojo.config.usePlainJson){				console.warn("Consider using mimetype:text/json-comment-filtered"					+ " to avoid potential security issues with JSON endpoints"					+ " (use djConfig.usePlainJson=true to turn off this message)");			}			return (xhr.status == 204) ? undefined : _d.fromJson(xhr.responseText);		},		"json-comment-filtered": function(xhr){ 			// NOTE: we provide the json-comment-filtered option as one solution to			// the "JavaScript Hijacking" issue noted by Fortify and others. It is			// not appropriate for all circumstances.			var value = xhr.responseText;			var cStartIdx = value.indexOf("\/*");			var cEndIdx = value.lastIndexOf("*\/");			if(cStartIdx == -1 || cEndIdx == -1){				throw new Error("JSON was not comment filtered");			}			return (xhr.status == 204) ? undefined :				_d.fromJson(value.substring(cStartIdx+2, cEndIdx));		},		"javascript": function(xhr){ 			// FIXME: try Moz and IE specific eval variants?			return _d.eval(xhr.responseText);		},		"xml": function(xhr){ 			var result = xhr.responseXML;			if(_d.isIE && (!result || window.location.protocol == "file:")){				_d.forEach(["MSXML2", "Microsoft", "MSXML", "MSXML3"], function(prefix){					try{						var dom = new ActiveXObject(prefix + ".XMLDOM");						dom.async = false;						dom.loadXML(xhr.responseText);						result = dom;					}catch(e){ /* Not available. Squelch and try next one. */ }				});			}			return result; // DOMDocument		}	};	dojo._contentHandlers["json-comment-optional"] = function(xhr){		var handlers = _d._contentHandlers;		try{			return handlers["json-comment-filtered"](xhr);		}catch(e){			return handlers["json"](xhr);		}	};	/*=====	dojo.__IoArgs = function(){		//	url: String		//		URL to server endpoint.		//	content: Object?		//		Contains properties with string values. These		//		properties will be serialized as name1=value2 and		//		passed in the request.		//	timeout: Integer?		//		Milliseconds to wait for the response. If this time		//		passes, the then error callbacks are called.		//	form: DOMNode?		//		DOM node for a form. Used to extract the form values		//		and send to the server.		//	preventCache: Boolean?		//		Default is false. If true, then a		//		"dojo.preventCache" parameter is sent in the request		//		with a value that changes with each request		//		(timestamp). Useful only with GET-type requests.		//	handleAs: String?		//		Acceptable values depend on the type of IO		//		transport (see specific IO calls for more information).		//	load: Function?		//		function(response, ioArgs){}. response is an Object, ioArgs		//		is of type dojo.__IoCallbackArgs. The load function will be		//		called on a successful response.		//	error: Function?		//		function(response, ioArgs){}. response is an Object, ioArgs		//		is of type dojo.__IoCallbackArgs. The error function will		//		be called in an error case. 		//	handle: Function?		//		function(response, ioArgs){}. response is an Object, ioArgs		//		is of type dojo.__IoCallbackArgs. The handle function will		//		be called in either the successful or error case.  For		//		the load, error and handle functions, the ioArgs object		//		will contain the following properties: 		this.url = url;		this.content = content;		this.timeout = timeout;		this.form = form;		this.preventCache = preventCache;		this.handleAs = handleAs;		this.load = load;		this.error = error;		this.handle = handle;	}	=====*/	/*=====	dojo.__IoCallbackArgs = function(args, xhr, url, query, handleAs, id, canDelete, json){		//	args: Object		//		the original object argument to the IO call.		//	xhr: XMLHttpRequest		//		For XMLHttpRequest calls only, the		//		XMLHttpRequest object that was used for the		//		request.		//	url: String		//		The final URL used for the call. Many times it		//		will be different than the original args.url		//		value.		//	query: String		//		For non-GET requests, the		//		name1=value1&name2=value2 parameters sent up in		//		the request.		//	handleAs: String		//		The final indicator on how the response will be		//		handled.		//	id: String		//		For dojo.io.script calls only, the internal		//		script ID used for the request.		//	canDelete: Boolean		//		For dojo.io.script calls only, indicates		//		whether the script tag that represents the		//		request can be deleted after callbacks have		//		been called. Used internally to know when		//		cleanup can happen on JSONP-type requests.		//	json: Object		//		For dojo.io.script calls only: holds the JSON		//		response for JSONP-type requests. Used		//		internally to hold on to the JSON responses.		//		You should not need to access it directly --		//		the same object should be passed to the success		//		callbacks directly.		this.args = args;		this.xhr = xhr;		this.url = url;		this.query = query;		this.handleAs = handleAs;		this.id = id;		this.canDelete = canDelete;		this.json = json;	}	=====*/	dojo._ioSetArgs = function(/*dojo.__IoArgs*/args,			/*Function*/canceller,			/*Function*/okHandler,			/*Function*/errHandler){		//	summary: 		//		sets up the Deferred and ioArgs property on the Deferred so it		//		can be used in an io call.		//	args:		//		The args object passed into the public io call. Recognized properties on		//		the args object are:		//	canceller:		//		The canceller function used for the Deferred object. The function

⌨️ 快捷键说明

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