下面图老师小编要向大家介绍下构建pool管理无刷新页面的xmlhttp对象,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!
【 tulaoshi.com - Web开发 】
在页面上使用ActiveXObject的代价是很大的,如果我们的无刷新页面使用xmlhttp技术,我们或许需要频繁的建立xmlhttp对象,当然我们也可以使用全局变量来cache一个xmlhttp对象实例。但是这样的方法适合于同步方式xmlhttp通信,而对于异步方式xmlhttp通信将会出现问题。由于没有了进程的堵塞,用户可能再次调用同一个xmlhttp实例,如果这时前一个通信未完成,那么就失败了。
var __XmlHttpPool__ =
{
m_MaxPoolLength : 10,
m_XmlHttpPool : [],
__requestObject : function()
{
var xmlhttp = null;
&nb {
return this.__extendPool();
}
return xmlhttp;
},
__extendPool : function()
{
if ( this.m_XmlHttpPool.length this.m_MaxPoolLength )
{
bsp; xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e2) {}
}
if ( xmlhttp )
{
this.m_XmlHttpPool.push(xmlhttp);
}
return xmlhttp;
&nb },
__receiveRemoteData : function(url, callback, httpmethod, data)
{
var xmlhttp = this.__requestObject();
if ( !xmlhttp )
{
return null;
}
xmlhttp.open(httpmethod, url, true);
&nbs是服务器地址,callback是处理返回数据(responseText)的回调函数。比如: (本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)script language="javascript"
__XmlHttpPool__.PostRemoteData(url, Render, 'abc'); 
function Render(string)
{
if ( string )
{
txbContent.value += string + 'rn';
}
来源:http://www.tulaoshi.com/n/20160219/1609928.html
看过《构建pool管理无刷新页面的xmlhttp对象》的人还看了以下文章 更多>>