3

ajax から読み込まれたデータのツールチップがあります。

$('.show_tooltip').hover(
    function(){
        $.post('getdata.php', function(data)    {
            $('#tooltip').html(data);
            $('#tooltip').show()
        });
    },
    function(){
        $('#tooltip').hide(); 
    }
);

できます。
しかし、問題は、要素の上にカーソルを置いてマウスをすばやく移動すると、$('#tooltip').show()効果がなく、hide(). しかし、データが読み込まれると、ポップアップ表示され、ホバーなしで表示されたままになります。

それについて何ができるか。投稿リクエストを完全に停止する方法はありますか?

4

4 に答える 4

5

jQuery AJAX メソッドは、リクエストを停止するメソッドを持つネイティブ オブジェクトjqXHRの拡張であるオブジェクトを返します。XMLHttpRequestabort

var xhr;
$('.show_tooltip').hover(
    function(){
        //Save reference to the jqXHR object
        xhr = $.post('getdata.php', function(data) {
            $('#tooltip').html(data);
            $('#tooltip').show()
        });
    },
    function(){
        xhr.abort(); //Abort the request
        $('#tooltip').hide(); 
    }
);
于 2012-05-08T09:08:28.967 に答える
0

あなたはこれを試すことができます:

$('.show_tooltip').hover(
    function(){
        $.post('getdata.php', function(data)    {
            $('#tooltip').html(data);
            $('#tooltip').show()
        });
    }
);
$('#tooltip').bind("mouseleave", function(){
    $(this).hide();
});
于 2012-05-08T09:09:15.363 に答える
0

この投稿は一度コードevent.preventDefault(); 例:

$("#formName").submit(function(event) {
    event.preventDefault(); // here using code stop post (return false;)
    $.post('processing.php', $("#formName").serialize(), function(result){ $('#LimitlessDiv').html(result); });
});
于 2012-11-13T10:16:30.247 に答える
0

.show()AJAX 成功関数を利用する必要があります。

$('.show_tooltip').hover(
    function(){
        $.ajax({
            type: 'POST',
            url: 'getdata.php',
            asynch
            data: data,
            success: function(){
                $('#tooltip').html(data);
            }
            $('#tooltip').show()
        });
    },
    function(){
        $('#tooltip').hide(); 
    }
);
于 2012-05-08T09:06:14.930 に答える