javascript - mouseover/mouseout events with ajax requests -
this question has answer here:
- jquery mouseover , mouseout bug 1 answer
i ran issue , wish top ideas here. here how code looks like:
$(document).on('mouseover', '#element', function(){ $.ajax({ // generate hover view }) }); $(document).on('mouseout', '#element', function(){ // remove hover view });
the correct execution order mouseover - generate view - mouseout - hide view.
however since view part depends on ajax, there chance mouseout event gets fired before ajax call finishes if user hovers super fast. in case, after ajax call completed, view going sit in dom without going away, since mouseout event fired.
did try using promises? need tweaked like:
$.when( $.ajax( "someajaxfile.txt" ) ).then(function( data, textstatus, jqxhr ) { $(document).on('mouseout', '#element', function(){ // remove hover view }); });
you may need unbind mouseout well.
Comments
Post a Comment