这是为什么jQuery的AJAX点击事件触发多次? [英] Why is this jQuery ajax click event firing multiple times?

查看:455
本文介绍了这是为什么jQuery的AJAX点击事件触发多次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解除绑定click事件,但它触发有时两次有时5倍!变得有点厌倦了吧!

I have tried unbinding the click event, but it fires sometimes twice sometimes 5 times!! Getting a bit fed up now!

$ C $从 modal.asp

$("input[name=add_associate]").live("click",function(){
    var addassociateID = $(this).attr("id")

    $.ajax({
       type: 'POST',
       url: '/data/watchlist_save.asp',
       data: {m : 'share_watchlist_add', watchListID : <%=WatchListID%>, a : addassociateID},
       async:true,
       success: function(data) {
           $(".associate_users").load("/data/sub_watch_members.asp?watchListID=<%=WatchListID%>",
           {cache:false},function() {
               $(".search_note").html(data)         
               $(this).unbind('click').bind('click',handler);                                                                                                
           })
       },
       error: function(data){
           $(".search_note").html(data)
       }
    });     
})

更新
基本上我打电话以下code到 .associate_users

UPDATE:
Basically I am calling the following code into .associate_users

<div id="associate_list">
    <div class="associate_record">
        <div class="left" style="padding:8px;"><img src="../imgs/nopic-m.png" style="width:30px;height:30px;" class="img_border" /></div>
        <div class="left" style="padding-top:15px;">5)Neil Burton</div>
        <div class="right" style="padding-top:10px;margin-right:5px;"><input type="button" class="btn-blue" name="add_associate" id="890" value="Add"></div>
        <div style="clear:both;"></div>
    </div>
    <div style="clear:both;"></div>
</div>

进一步信息
这只是发生在我触发事件,关闭模态对话框,然后重新打开它用不同的 watchListID

FURTHER INFORMATION:
This only happens when I fire the event, close the modal dialog then re-open it with a different watchListID

数据的结构:

  • main.asp :荷载>
  • modal.asp :modal.asp包含上述+两个div此页面上了jQuery与panel1.asp和panel2.asp数据...
  • panel1.asp :包含上面的HTML ...
  • panel2.asp :不包含任何相关的...只是纯HTML
  • main.asp: LOADS >
  • modal.asp: modal.asp contains the jquery from above + two divs on this page with panel1.asp and panel2.asp data...
  • panel1.asp: Contains the HTML above...
  • panel2.asp: Contains nothing related... just pure HTML.

推荐答案

我已经解决了这个问题,现在,我是用

I have resolved this issue now, I was using

$(document).ready

在装载Ajax内容以及...

in the loaded ajax content along with...

<script src="/js/jquery-ui.js"></script>

所以我presume它加倍的活的功能!

So I presume it was doubling up the "live" function!

感谢你这么多的响应。

这篇关于这是为什么jQuery的AJAX点击事件触发多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆