使用jQuery我怎么可以检测正在完成'任何'Ajax请求? [英] How can I detect 'any' ajax request being completed using jQuery?

查看:137
本文介绍了使用jQuery我怎么可以检测正在完成'任何'Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我可以插入一些JavaScript / jQuery来操纵输出。我没有任何其他的控制页面标记等。

I have a page where I can insert some javascript / jquery to manipulate the output. I don't have any other control over the page markup etc.

我需要通过jQuery后,页面上的每个present添加一个额外的元素。的问题是,经由发生后$(文件)。准备完成已有页上的异步调用生成的元素。

I need to add an extra element via jquery after each present on the page. The issue is that the elements are generated via an asynchronous call on the existing page which occurs after $(document).ready is complete.

从本质上讲,我需要调用我的jQuery后,页面加载和后续的Ajax调用已经完成的一种方式。有没有一种方法来检测完成页面上的任何Ajax调用,然后调用自己的自定义功能,插入新创建秒之后,附加元素?

Essentially, I need a way of calling my jquery after the page has loaded and the subsequent ajax calls have completed. Is there a way to detect the completion of any ajax call on the page and then call my own custom function to insert the additional elements after the newly created s ?

推荐答案

不幸的是,这并不适用,因为它似乎在OP没有使用的的 $。阿贾克斯() 或任何jQuery的AJAX方法实际加载的内容,但在这里留下未来的情况下,Google员工的正在做这件事。

您可以使用任何这里满足您的需求,全球AJAX事件,你以后 $很可能。ajaxComplete() 或<一HREF =htt​​p://api.jquery.com/ajaxSuccess/> $。的ajaxSuccess()

You can use any of the global ajax events that meet your needs here, you're probably after $.ajaxComplete() or $.ajaxSuccess().

例如:

$(document).ajaxSuccess(function() {
  alert("An individual AJAX call has completed successfully");
});
//or...
$(document).ajaxComplete(function() {
  alert("ALL current AJAX calls have completed");
});

如果你想运行只是一些普通的功能,然后将其附加文件(他们只是事件的下方)。如果你想显示什么特别的,例如一个模式或消息,你可以用它们有点整洁(尽管这似乎并不为你以后有什么),像这样的:

If you want to run just some generic function then attach them to document (they're just events underneath). If you want to show something in particular, for example a modal or message, you can use them a bit neater (though this doesn't seem to be what you're after), like this:

$("#myModal").ajaxComplete(function() {
  $(this).fadeIn().delay(1000).fadeOut();
});

这篇关于使用jQuery我怎么可以检测正在完成'任何'Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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