`
wfdoublext
  • 浏览: 126173 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

many request

    博客分类:
  • ajax
阅读更多
* XMLHttpRequest Object Pool
*
* @author legend <legendsky@hotmail.com>
* @link http://www.ugia.cn/?p=85
* @Copyright www.ugia.cn
*/ 
var XMLHttp = {
				_objPool: [],
				_getInstance: function ()
				{
					for (var i = 0; i < this._objPool.length; i ++)
					{
						if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4)
						{
							return this._objPool[i];
						}
					}
					// IE5中不支持push方法
					this._objPool[this._objPool.length] = this._createObj();
					return this._objPool[this._objPool.length - 1];
				},


				_createObj: function ()
				{
					if (window.XMLHttpRequest)
					{
						var objXMLHttp = new XMLHttpRequest();
					}
					else
					{
						var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
						for(var n = 0; n < MSXML.length; n ++)
						{
							try
							{
								var objXMLHttp = new ActiveXObject(MSXML[n]);
								break;
							}
							catch(e)
							{
							}
						}
					} 
					// mozilla某些版本没有readyState属性
					if (objXMLHttp.readyState == null)
					{
						objXMLHttp.readyState = 0;
						objXMLHttp.addEventListener("load", function ()
						{
							objXMLHttp.readyState = 4;
							if (typeof objXMLHttp.onreadystatechange == "function")
							{
								objXMLHttp.onreadystatechange();
							}
						}, false);
					}
					return objXMLHttp;
				},


				// ?送?求(方法[post,get], 地址, 数据, 回?函数)
				sendReq: function (method, url, data, callback)
				{
					var objXMLHttp = this._getInstance();
					with(objXMLHttp)
					{
						try
						{
							// 加随机数防止?存
							if (url.indexOf("?") > 0)
							{
								url += "&randnum=" + Math.random();
							}
							else
							{
								url += "?randnum=" + Math.random();
							}
						open(method, url, true);
						// ?定?求??方式
						setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
						send(data);
							onreadystatechange = function ()
							{
								if (objXMLHttp.readyState == 4 && (objXMLHttp.status == 200 || objXMLHttp.status == 304))
								{
									callback(objXMLHttp);
								}
							}
						}
						catch(e)
						{
							alert(e);
						}
					}
				}
}; 


示例: 

<mce:script type="text/javascript" src="xmlhttp.js" mce_src="xmlhttp.js"></mce:script>
<mce:script type="text/javascript"><!--
function test(obj)
{
alert(obj.statusText);
}
XMLHttp.sendReq('GET', 'http://www.ugia.cn/wp-data/test.htm', '', test);
XMLHttp.sendReq('GET', 'http://www.ugia.cn/wp-data/test.htm', '', test);
XMLHttp.sendReq('GET', 'http://www.ugia.cn/wp-data/test.htm', '', test);
XMLHttp.sendReq('GET', 'http://www.ugia.cn/wp-data/test.htm', '', test);
alert('Pool length:' + XMLHttp._objPool.length);
// --></mce:script> 
 
分享到:
评论

相关推荐

    基于C#的爬虫系统-抓取百万知乎用户数据并存储到SqlServer数据库 含爬虫设计思路、源代码、数据分析结果.rar

    爬取太频繁会被知乎返回429(too many request),应对的策略是挂代理,一种方法是使用专业的云代理服务(有点贵),另一种是[自建代理池],定时爬取互联网上免费代理ip。最后数据使用sql server存储, 最后对数据进行...

    esp-quota-limit

    OpenApi文档中的ESP测试配额 测试它的前提条件 创建一个Google Cloud Platform项目并指定get ...是每分钟,因此,如果我们收到状态码429 Too Many Request并且等待一分钟,我们应该没问题,但是等待一分钟后下一个请

    ZeroMQ: Messaging for Many Applications

    Learn ØMQ’s main patterns: request-reply, publish-subscribe, and pipeline Work with ØMQ sockets and patterns by building several small applications Explore advanced uses of ØMQ’s request-reply ...

    many-to-many:Laravel Nova的内联多态和非多态`ManyToMany`字段

    目录特征在创建和更新页面中附加多态和非多态的ManyToMany关系附加关系时编辑枢轴列将源多次附加到另一个资源安装composer require armincms/many-to-many简单用法 use Armincms\Fields\BelongsToMany; /** * Get ...

    RFC4244.An_Extension_to_SIP_for_Request_History_Information

    This document defines a standard mechanism for capturing the history information associated with a Session Initiation Protocol (SIP) request. This capability enables many enhanced services by ...

    nova-attach-many:BelongsToMany为Nova创建编辑表单组件

    安装composer require dillingham/nova-attach-many用法use NovaAttachMany \ AttachMany ; public function fields ( Request $ request ){ return [ AttachMany :: make ( 'Permissions' ), ];} 您可以显式定义...

    Systems Modeling Language (SysML®) v2 Request For Proposal (RFP)

    many of the limitations of the current version of OMG SysML® to enable the more effective application of model-based systems engineering (MBSE). In particular, the emphasis for SysML v2 is to ...

    flask_pydantic:用于扩展真棒pydantic软件包的flask扩展

    烧瓶-釜山 Flask扩展,用于将强大的与集成。安装python3 -m pip install Flask-Pydantic 基本validate装饰器验证查询和主体请求参数并使它们可通过两种... 设置为False request_body_many参数可以在请求正文的根级别

    Dicoman 4.8.6 Build 1172 Dicoman最新版

    For many users of Windows 7 and above, installation is not needed. You simply download the package and unzip it to a folder. If that did not work out, you may have to install needed runtimes. ...

    解决环信io.swagger.client.ApiException包报错

    解决环信io.swagger.client.ApiException包报错以及环信默认包导入工程后的报错问题

    Jump Start PHP Environment(SitePoint,2015)

    Many entry level PHP developers want a quick path to glory, a shortcut to “knowing PHP.” Too many books and tutorials go straight into a pre-made, awful environment that just wants you to code, with...

    httpd-2.4.28

    It is now possible to Define variables in the configuration, allowing a clearer representation if the same value is used at many places in the configuration. Reduced memory usage Despite many new ...

    Android代码-AntennaPod

    Bug reports and feature requests can be submitted here (please read the instructions on how to report a bug and how to submit a feature request first!). Help test AntennaPod AntennaPod has many users ...

    Hypertext Transfer Protocol -- HTTP/1.0

    stateless, object-oriented protocol which can be used for many tasks, such as name servers and distributed object management systems, through extension of its request methods (commands). A feature of ...

    An Experimental Comparison of Min-Cut/Max-Flow Algorithms

    最大流/最小割算法的简介,理解常用最大流最小割概念的文献,值得学习。 minimum cut/maximum flow ... An implementation of our max-flow/min-cut algorithm is available upon request for research purposes.

    OBD-PID.pdf

    OBD-II PIDs (On-board diagnostics Parameter IDs) are codes used to request data from a vehicle, used as a diagnostic tool. SAE standard J/1979 defines many PIDs, but manufacturers also define many ...

    DirectShow学习资料

    and is an extensible, filter-based framework that can render or record media files on demand at the request of the user or developer. The DirectShow development tools and documentation were ...

    Android代码-reactivesocket-java

    request/stream (finite stream of many) fire-and-forget (no response) event subscription (infinite stream of many) Learn more at http://rsocket.io Build and Binaries Releases are available via Maven ...

    Adobe.Press.CSS.Animations.and.Transitions.for.the.Modern.Web.0133980502.pdf

    Modern websites use a variety of animated ... Some of these effects require complex scripting or programming skills, but many are within the grasp of designers who are already familiar with CSS and ...

Global site tag (gtag.js) - Google Analytics