javascript - mouseover/mouseout events with ajax requests -


this question has answer here:

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

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -