I use a function to load a page with jQuery but only after a certain delay after hovering over a li
. For that I use setTimeout
on the mouseover
and try to kill it on the mouseleave
if the mouse hovered for less than 500ms over the li
. However, the jQuery.ajax
still launches, so basically, if I hover over all li
s, that will launch plenty of xhr even if I stay only 1ms on the li
.
var timer2;
var delay2 = 500;
$('body').on('mouseover','li',function(){
timer2 = setTimeout(function() {
var url="res.php";
jQuery.ajax(
{
type: 'POST',
url:url,
success: function(data){
$('#res').html(data);
}
});
}, delay2);
});
$('body').on('mouseleave', 'li', function() {
clearTimeout(timer2);
});