AJAX div 的错误处理

发布于 2024-07-25 13:28:56 字数 876 浏览 3 评论 0原文

我一直在使用一个非常有用的基于 AJAX 的脚本,名为 AJAXTwits 将运动队的多个 Twitter 时间线加载到 div 中。 该脚本的优点在于,它 (1) 将多个时间线合并为一个按时间顺序排列的时间线,并且 (2) 缓存 xml 以加快加载速度。 不过,Twitter 的提要经常会出现故障,这意味着 (i) 缓存失败,(ii) 内容无法加载(我被加载消息卡住了),以及 (iii) 如果问题足够大,整个页面(不仅仅是 div)中断并抛出 404 错误。

因此,我想添加错误处理 - 具体来说,如果内容未在设定的时间内加载,则预先编写的消息/div 内容将替换加载消息。 我在这个论坛上找到了一些关于如何处理超时的好例子。 但这些处理的是更简单的函数/脚本语法。 作为一名剪切/粘贴/模拟程序员,我很难适应这一点。

主要的 html 看起来像这样:

<ul id='AjaxTwits'>
    <li id='AjaxTwitsLoader'>
        <em>Loading tweets</em>
    </li>
</ul>

<script type="text/javascript">
    getAjaxTwits("AjaxTwits/AjaxTwitsRequest.php", 6);
</script>

在不深入研究脚本和 php 文件的情况下,是否有任何类型的错误/超时处理可以放入此 html 中? 任何帮助表示赞赏!

I've been using a very helpful AJAX-based script called AJAXTwits to load multiple Twitter timelines for a sports team into a div. The nice thing about the script is that it (1) combines multiple timelines into one chronological timeline and (2) caches the xml for faster loading. Every so often, though, Twitter's feeds go down, meaning that (i) the caching fails, (ii) the content won't load (I get stuck with the loading message), and (iii) if the problem is big enough, the whole page (not just div) breaks and throws a 404 error.

So, I'd like to add error-handling -- specifically, a pre-written message/div-content that will replace the loading message if the content doesn't load within a set amount of time. I've found some nice examples on this forum on how to handle timeouts. But those deal with a much simpler function/script syntax. Being a cut/paste/emulate programmer, I'm having trouble adapting that.

The main html looks like this:

<ul id='AjaxTwits'>
    <li id='AjaxTwitsLoader'>
        <em>Loading tweets</em>
    </li>
</ul>

<script type="text/javascript">
    getAjaxTwits("AjaxTwits/AjaxTwitsRequest.php", 6);
</script>

Without digging into the script and php files, is there any kind of error/timeout handling that can be placed into this html? Any help appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生殊途 2024-08-01 13:28:56

我之前没有使用过这个脚本,因此我无法在这方面为您提供帮助,但我可以推荐我一直在使用的在我的应用程序上显示 Twitter 消息的脚本。

这是一个 jquery 插件,您可以在这里找到:http://tweet.seaofclouds.com/

我不认为你会遇到同样的问题,因为它使用jquery来进行ajax调用。 值得一试。

希望能帮助到你。

I did not use this script before therefore i can't help you on this, but i can recommend what i've been using for showing twitter messages on my apps.

It is a jquery plugin which you can find here: http://tweet.seaofclouds.com/.

I don't think you will have the same problem, because it uses jquery to make the ajax call. It worths to try.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文