javascript - ajax prevent double posting on mouseenter -
can point out need in code stop doubling on data when mouseenter on hyperlink tag. put flag in there isloading still continues double up. i've done wrong have through code , see whats wrong - see if can prevent double posting on mouseenter. please show me you're changes - kdm.
(function($){ $.fn.rating_display = function() { var _this = this; var id = $(_this).data('id'); var position = $(this).parent().position(); var left = position.left - 15; var top = position.top + $(this).height() + 13; var isloading = false; function clear_ratings() { $('.ratings-content').html(""); } $(document).on('click', function(e) { var element = e.target; /*else if($(element).closest('.rating').length){ $('.ratings-display').show(); }*/ }); // here i'm having trouble double posting $(this).on('mouseenter click', function(e) { if(isloading == true) return false; $.ajax({ type:'post', datatype:"html", data:{product_id:id}, url:"../../webservices/get_rating.php", beforesend: function() { clear_ratings(); $('.ratings-display').show().css({'left':left + 'px', 'top':top + 'px'}); isloading = true; }, success: function(data) { $('.ratings-content').append(data); }, error:function(data, status, xhr) { clear_ratings(); $('.ratings-content').html(data + "\r\n" + status + "\r\n" + xhr); } }); }).on('mouseleave', function(e) { var target = e.relatedtarget; if($(target).closest('.ratings-display').length) { return false; }else{ $('.ratings-display').hide(); clear_ratings(); isloading = false; } }); $('.ratings-display').on('mouseleave',function (e) { var target = e.relatedtarget; if($(target).closest('.rating').length) return false; if(!$(target).closest('.ratings-display').length) { $('.ratings-display').hide(); clear_ratings();isloading = false; } }); } })(jquery);
'mouseenter click'
means action performed once @ mouseenter , again if click.
Comments
Post a Comment