I have a list of links wich point to html pages.
<ul id="item-list">
<li><a href="assets/data/item1.html">Item 1</a></li>
<li><a href="assets/data/item2.html">Item 2</a></li>
<li><a href="assets/data/item3.html">Item 3</a></li>
<li><a href="assets/data/item3.html">Item 4</a></li>
</ul>
And i have a javascript(jquery) wich recives and append the html to my document.
var request;
$('#item-list a').live('mouseover', function(event) {
if (request)
request.abort();
request = null;
request = $.ajax({
url: $(this).attr('href'),
type: 'POST',
success: function(data) {
$('body').append('<div>'+ data +'</div>')
}
});
});
I've tried to work with setTimeout() but it does not work as i aspected.
var request, timeout;
$('#item-list a').live('mouseover', function(event) {
timeout = setTimeout(function(){
if (request)
request.abort();
request = null;
request = $.ajax({
url: $(this).attr('href'),
type: 'POST',
success: function(data) {
$('body').append('<div>'+ data +'</div>')
}
});
}, 2000
);
});
How can i tell jquery to wait (500ms or 1000ms or …) on hover before sending the new request?