weixin_33739523 2012-04-11 09:35 采纳率: 0%
浏览 30

jQuery mouseleave ajax请求

I was wondering if it is possible for an ajax request to be triggered from a mouseleave function? I would like the string 'Y' to be sent on when the mouse leaves the li so it can be updated in the database.

is this possible by any chance?

(function(){
  $('li#myId').mouseenter(function(){
    var y = 'Y';
  }).mouseleave(function(){

    $.ajax({
      type: 'POST',
      url: 'update.php',
      data: 'y='+y,
      success: function(response){
        $('li.#myId').html(response);
      }

    });
  });

})();

  • 写回答

2条回答 默认 最新

  • bug^君 2012-04-11 09:42
    关注

    Sure, just store y as data.

    (function(){
        var postY = function (y) {
            $.ajax({
              type: 'POST',
              url: 'update.php',
              data: 'y='+y,
              success: function(response){
                  $('#myId').html(response);
              }
            });
        };
    
        // li#myId using both a tag and id is unnecessary since id is unique
        $('#myId').mouseenter(function(e){
            $(this).data('y', 'Y');
        }).mouseleave(function(e){
            postY($(this).data('y'));
        });
    })();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料