jQuery的阿贾克斯提示 [英] jQuery Ajax tooltip

查看:108
本文介绍了jQuery的阿贾克斯提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过这个jQuery插件做的Ajax工具提示: http://jquery.bassistance.de/提示/演示/

I try to do Ajax tooltip via this jQuery plugin: http://jquery.bassistance.de/tooltip/demo/

我有一些事情是这样的:

I have some thing like this:

<p id="foottip">
  <span href="/last_votes/6">footnote</span>.
</p>

<script type="text/javascript">
  $(function() {
    $("#foottip span").tooltip({
      bodyHandler: function() {
        //dj ajax here and cache
        var tip = ''
        var url = $(this).attr("href");

        $.ajax({
          url:url, success:function(html){tip = html;}, async:false
        });

        return tip
      },

      showURL: false
    });
  })
</script>   

我这样做,与异步Ajax请求,但解决的办法有问题,有时它重定向页面。这似乎是一个错误。我该怎么做一个Ajax工具提示使用异步请求?我找不到的方式来传递导致的异步提示。

I do it with an asynchronous Ajax request, but the solution has a problem, sometimes it redirects the page. It seems to be a bug. How can I do an Ajax tooltip with an asynchronous request? I can't find way to pass result to the tooltip asynchronously.

推荐答案

我抵靠在了同样的问题。发现了一个聪明的技术这里动态的bodyHandler回调创建一个元素,然后更新,在AJAX调用整齐地达到预期的效果。

I butted up against the same problem. Discovered a clever technique here that dynamically creates an element in the bodyHandler callback and then updates that in the AJAX call to neatly achieve the desired effect.

作为施加到上述问题:

$("#foottip span").tooltip({
    bodyHandler: function() {
        var url = $(this).attr("href");
        var tip = $("<span/>").html("loading tip...");

        $.ajax({
            url: url,
            success: function(html){ tip.html(html); }
        });

        return tip;
    },
    showURL: false
});

这篇关于jQuery的阿贾克斯提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆