jquery ui tabs ajax,jQuery UI ajax tabs - requests multiplying when loading links within tabs

问题

I'm using jQuery UI tabs, loading the tab content via ajax. Content may contain links which I want to load within the selected tab. To achieve that, I use this code

$("#tab-div").tabs({

load: function(event, ui) {

$('a:not('.targetBlank'), ui.panel).live('click', function() {

$(ui.panel).load(this.href);

return false;

});

});

I use live() so that the links loaded after the initial load are also covered.

Now, imagine a situation where you have 2 tabs. First, the user is in tab_a, which contains links. The user clicks a link within tab_a and it opens fine. Then, tab_b is selected, then tab_a, and the link within again.

so that's: tab_a -> link within -> tab_b -> tab_a -> link within

Now after tab_a is selected for the second time, and the link within after that, I get two requests when link is clicked. If I repeat the process, once I click on link within tab_a, I'll get three requests and so on.

I can't quite get the grip on what's going on in here.

.targetBlank class is for links that are not intended to open within a tab. It's not particularly relevant, but I thought I'd share it as well, if it turns out to be important somehow.

回答1:

You need to set a flag if the content has already been bound, or unbind the content on tab change.

Something like ui.panel.find('a').unbind() should do the trick. Make sure you put it in the tab change callback.

来源:https://stackoverflow.com/questions/4588423/jquery-ui-ajax-tabs-requests-multiplying-when-loading-links-within-tabs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值