中止的jQuery()。load()的 [英] Aborting jQuery().load()

查看:146
本文介绍了中止的jQuery()。load()的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 .load() 功能的 jQuery的库,您可以有选择地加载从另一个页面(受某些规则)的元素。我想知道是否有可能为终止加载过程。

The .load() function of the jQuery library allows you to selectively load elements from another page (subject to certain rules). I would like to know whether it is possible to abort the load process.

在我们的应用程序中,用户可以浏览的项目的列表。他们可以选择点击一个按钮,加载和显示有关从另一个文件(这可能需要一些时间)项的附加信息。如果他们选择的,而列表中的不同项的 .load()仍然发生,我想装载被放弃。

In our application, a user can browse a list of items. They may choose to click a button which loads and displays additional information about an item from another document (which can take some time). If they choose a different item in the list whilst a .load() is still happening, I would like the loading to be aborted.

这可能吗?它甚至值得吗?任何想法?

Is this possible? Is it even worth it? Any ideas?

推荐答案

您不能做到这一点与 。负载() 直接,因为它返回链接jQuery对象,但如果你改变到完全的 $。阿贾克斯() <$ C $致电C>的.html() 就可以了,像这样的:

You can't do this with .load() directly, since it returns the jQuery object for chaining, but if you change to the full $.ajax() call with .html() you can, like this:

var xhr = $.ajax({
            url: 'mypage.htm',
            success: function(data) {
              $("#myElement").html(data);
            }
          });
//if needed, abort the request later..
xhr.abort();

本使用上XMLHtt $的 .abort()方法p $ pquest对象以中止负载。

This uses the .abort() method on the XMLHttpRequest object to abort the load.

这篇关于中止的jQuery()。load()的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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