jQuery MouseEnter与Ajax问题?

时间:2012-02-06 13:11:11

标签: ajax mouseenter

我遇到以下逻辑问题 - 因为ajax请求多次运行而我只希望它运行一次?

var currentItem = jQuery('#specialId .myclass');

currentItem.mouseenter(function() {
    jQuery.ajax({
        type: "POST",
        url: "/url/data",
        data: "myData=" + dataNow,
        cache: false,
        success: function(html) {
            //do stuff
        }
    });
});

问题是我有一堆.myClass,这意味着ajax请求会多次运行。当用户进入他们正在输入的currentItem时,如何让它只运行一次?

1 个答案:

答案 0 :(得分:0)

currentItem.one("mouseenter", function () {

    // rest of implementation

});

......问题解决了。