jQuery中的AJAX回发

问题描述 投票:1回答:2

我在页面上有一个AJAX请求。

有没有办法找到何时在页面上触发AJAX调用。在jQuery或javascript中查找或启动一个带有AJAX请求的函数在页面上调用。

javascript ajax jquery
2个回答
2
投票

ajaxStartajax events。例:

 $("#loading").bind("ajaxSend", function(){
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });

0
投票

您可以将函数绑定到JQuery对象,以便在任何AJAX调用完成时完成。

$('#status').ajaxComplete(function(event, request, settings) {
    // Do stuff here...
});

the documentation

如果要为单个AJAX调用设置完整函数,请使用低级$.ajax()函数并为complete属性设置函数。

$.ajax({
    // ...
    complete: function(request, settings) {
         // Do stuff here...
    },
    // ...
});

注意:在指定complete()函数的参数数量时,文档似乎自相矛盾。这可能需要一些摆弄。

© www.soinside.com 2019 - 2024. All rights reserved.