* 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>
分享到:
相关推荐
爬取太频繁会被知乎返回429(too many request),应对的策略是挂代理,一种方法是使用专业的云代理服务(有点贵),另一种是[自建代理池],定时爬取互联网上免费代理ip。最后数据使用sql server存储, 最后对数据进行...
JAVA.NET.SOCKETEXCEPTION TOO MANY OPEN FILES解决方法 JAVA.NET.SOCKETEXCEPTION TOO MANY OPEN FILES错误是一种常见的网络编程错误,发生在Java应用程序中, especialmente 在 Linux 操作系统中。该错误的出现是...
OpenApi文档中的ESP测试配额 测试它的前提条件 创建一个Google Cloud Platform项目并指定get ...是每分钟,因此,如果我们收到状态码429 Too Many Request并且等待一分钟,我们应该没问题,但是等待一分钟后下一个请
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 ...
常见的关系类型包括一对一(hasOne)、一对多(hasMany)、多对一(belongsTo)、多对多(belongsToMany)等。 在Laravel请求处理中,通常我们会使用`Request`类来接收和验证用户提交的数据。`Request`对象是...
目录特征在创建和更新页面中附加多态和非多态的ManyToMany关系附加关系时编辑枢轴列将源多次附加到另一个资源安装composer require armincms/many-to-many简单用法 use Armincms\Fields\BelongsToMany; /** * Get ...
安装composer require dillingham/nova-attach-many用法use NovaAttachMany \ AttachMany ; public function fields ( Request $ request ){ return [ AttachMany :: make ( 'Permissions' ), ];} 您可以显式定义...
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扩展,用于将强大的与集成。安装python3 -m pip install Flask-Pydantic 基本validate装饰器验证查询和主体请求参数并使它们可通过两种... 设置为False request_body_many参数可以在请求正文的根级别
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包报错以及环信默认包导入工程后的报错问题
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...
print(response.request.headers) ``` 这样,服务器会认为请求来自一个真实的浏览器,而不是无头爬虫,可能会避免因策略导致的重定向。 2. 禁止重定向 在某些情况下,你可以选择完全禁止`requests`库执行任何...
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 ...
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 ...
- 如果查询参数涉及到关联模型,可以使用Eloquent的关系方法(如`hasMany`, `belongsTo`等)来获取关联数据。 10. **API响应**: - 对于API开发,可以使用`Response` facade或`response()`辅助函数来构造JSON响应...
最大流/最小割算法的简介,理解常用最大流最小割概念的文献,值得学习。 minimum cut/maximum flow ... An implementation of our max-flow/min-cut algorithm is available upon request for research purposes.
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 ...
1. svn: Server sent unexpected return value (500 Internal Server Error) in response to OPTIONS request for 'http://svn.moon.ossxp.com/svn/test' 该错误提示的原因是用户名输入错误。解决方法是检查登录的...
在IT领域,TMF814标准主要用于电信管理网(Telecommunications Management Network, TMN)中的接口定义,其中涉及到ORB(Object Request Broker,对象请求代理)技术,如CORBA(Common Object Request Broker ...