【发布时间】:2015-02-20 22:30:07
【问题描述】:
我是一个老(大约 2008 年)Flash 人,更多的是设计师而不是程序员。好几年没编程了。
我正在尝试在我正在构建的网站上实现 Tooltipster(都是 html/jQuery),只有一种用法,但我需要能够按需加载内容,这样我才不会' t 有一个巨大的初始负载......一个页面上会有几十个;即一个工具提示,您可以单击其中的链接,并包含图像和文本(以及任何其他 html),并且在您移出内容区域之前不会消失。
在Tooltipster主页上,有关于用ajax加载的信息,但我不太明白。
简单来说,如何将以下代码转换为 ajax-load 实例?如前所述,一个页面上可能有很多这样的内容。例如,我认为 demo-interact 需要是一个 html 页面,所有其他实例也是如此,但我在这里不合群:
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<tr>
<td> <a href="#"><span id="demo-interact"
title="Try clicking
<a href='http://google.com/' target='_blank'>
this link
</a>
<strong>
This text is in bold case!
</strong>
<img src='spiderman.png'/>
">This</span></a> will hover until you move away from the tooltip itself, i.e. it's clickable</td>
<td> </td>
</tr>
</table>
在项目的主页上,它显示了如何使用 ajax 加载 html 文件,但正如我所说,它有点超出我的能力。我假设包含标签需要一个 ID,并且该 ID 将被传递给函数而不是 example.php(如下),,或类似的东西?
$('.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');
}
});
}
}
});
一切都来自这里:http://iamceege.github.io/tooltipster/#demos
任何帮助将不胜感激:)
肖恩
【问题讨论】:
-
您是否安装了响应
example.php的网络服务器? -
我在 Internic.ca 有服务器空间,允许使用 php,但现在我正在使用 localhost,并且不打算使用任何 php。而且我在本地使用 WampServer64,所以我这里也有 php。但同样,在这个阶段,我不打算使用 jquery/ajax/xml 以外的任何东西。
-
AJAX 是一个与服务器异步通信的概念。这意味着,当您可以通过 HTTP 与服务器交互时,该站点不需要重新加载。根据浏览器的不同,从本地文件系统加载
example.php可能不起作用。
标签: jquery ajax tooltipster