如果有多个链接,则ajax POST调用重复

时间:2014-05-01 19:39:03

标签: javascript jquery ajax

我有很奇怪的问题,我无法理解它的错误。

HTML code:

<a data-toggle="popover" data-trigger="hover" data-html="true" data-selfid="{$id}"  data-filter="XO" data-placement='left'> Item 1</a>

jQuery代码:

        $('*[data-selfid]').mouseenter(function(event) {
            var e=$(this);
            e.popover({html:true,placement:'right', content:"Loading..."}).popover('show')
            $.ajax({
                type: "POST",
                url: '/ajax/getitemdescription/',
                data: {id : e.data('selfid'), filter :e.data('filter')},
                statusCode: {
                         204: function() {
                         $('.popover-content:visible').html('<div>Nothing found</div>')
                         }
                },
                success: function(rply){
                $('.popover-content:visible').html(rply)
            }})
        });

现在,如果我的页面上有4个链接,就像这样

Item 1
Item 2
Item 3
Item 4

当我将鼠标悬停在链接第1项上时,它会发送4个POST请求。当我将鼠标悬停在第2项上时,它会发送3个POST请求,依此类推。如果我将鼠标悬停在最后一个链接上(在本例中为Link 4),它会发送一个类似应该发出的POST请求。

它到底有什么问题?请帮忙。

0 个答案:

没有答案