【问题标题】:jQuery plugin Tooltipster giving error for ajax call to load conentjQuery 插件 Tooltipster 为加载内容的 ajax 调用提供错误
【发布时间】:2016-07-02 22:26:57
【问题描述】:

我有如下代码,错误来自 instance.content() 行。我正在动态加载所有内容并在下面为所有 href 标签执行。 错误是 未捕获的 TypeError:instance.content 不是函数 我该如何解决这个问题

ex.find("a[href]").each(function (idx, el) {
var el = $(el);
var url = el.prop("href").substring(4);
el.attr("href", "");
el.addClass("popuplink");

el.tooltipster({
    content: 'Loading...',
    // 'instance' is basically the tooltip. More details in the "Object-oriented Tooltipster" section.
    functionBefore: function (instance, helper) {

        var $origin = $(helper.origin);

        // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
        if ($origin.data('loaded') !== true) {

            $.get(url, function (data) {

            // call the 'content' method to update the content of our tooltip with the returned data
            instance.content(data);

            // to remember that the data has been loaded
             $origin.data('loaded', true);
            });
        }
    }

});

});

【问题讨论】:

    标签: jquery ajax tooltipster


    【解决方案1】:

    确保您使用的是 Tooltipster v4 的文件。我看不出它不能与您提供给我们的代码一起使用的其他原因。

    【讨论】:

      【解决方案2】:

      如果其他人在使用 V3 时遇到此问题并希望它适用于 V3 而不是 V4,您可以在此处查看旧文档:

      https://web.archive.org/web/20140404021936/http://iamceege.github.io/tooltipster#advanced

      基本上,它们确实改变了不同版本之间功能的工作方式,因此令人困惑。一个可行的 V3 示例可能是:

      $('.tooltip').tooltipster({
          content: 'Loading...',
          functionBefore: function(origin, continueTooltip) {
      
              // we'll make this function asynchronous and allow the tooltip to go ahead and show the loading notification while fetching our data
              continueTooltip();
              
              // next, we want to check if our data has already been cached
              if (origin.data('ajax') !== 'cached') {
                  $.ajax({
                      type: 'POST',
                      url: 'example.php',
                      success: function(data) {
                          // update our tooltip content with our returned data and cache it
                          origin.tooltipster('content', data).data('ajax', 'cached');
                      }
                  });
              }
          }
      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多