解决jQuery插件tipswindown与hintbox冲突

本文介绍了解决tipswindown插件与hintbox插件在使用过程中产生的冲突问题,通过修改jQuery的ajaxStart事件处理函数,避免了两者共用同一个XHR对象导致的问题。

先扫下盲:tipswindown是jQuery的弹窗插件,可以使用url或当前页元素显示在模拟层中;hintbox是jQuery的类似Google Suggestions插件。

使用情形如下:

 

页面a.aspx中点击按钮弹出模拟层,在这个层中有一个输入文本框“监督人”处调用hintbox来产生即时查询功能。

直接调用产生了如下情形:

于是找到jquery.hintbox-1.3.js这个文件,发现其中出现这么一行:

 


  
$( " #windown-content " ).ajaxStart( function (){
$(
this ).html( " <img src=' " + templateSrc + " /images/loading.gif' class='loading' /> " );
});

 

将其改为:

 

 


  
$( " #windown-content " ).html( " <img src=' " + templateSrc + " /images/loading.gif' class='loading' /> " );

 

原因是两个插件即使是在不同情形下触发ajax事件,使用的仍是同一对象,即jQuery.js中出现的

 

 

代码

   
ajaxSetup: function ( settings ) {
jQuery.extend( jQuery.ajaxSettings, settings );
},

ajaxSettings: {
url: location.href,
global:
true ,
type:
" GET " ,
contentType:
" application/x-www-form-urlencoded " ,
processData:
true ,
async:
true ,
/*
timeout: 0,
data: null,
username: null,
password: null,
*/
// Create the request object; Microsoft failed to properly
// implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
// This function can be overriden by calling jQuery.ajaxSetup
xhr: function (){
return window.ActiveXObject ? new ActiveXObject( " Microsoft.XMLHTTP " ) : new XMLHttpRequest();
},
accepts: {
xml:
" application/xml, text/xml " ,
html:
" text/html " ,
script:
" text/javascript, application/javascript " ,
json:
" application/json, text/javascript " ,
text:
" text/plain " ,
_default:
" */* "
}
},

 

这样在当前窗体中就会是只有一个xhr对象存在,因为在hintbox中的ajax事件会触发tipswindown的ajaxStart事件。

 

可下载修改过后的tipswindown,点击下载

转载于:https://www.cnblogs.com/walkingp/archive/2010/11/03/1867934.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值