George_Fal 2015-09-21 12:25 采纳率: 0%
浏览 41

AjaxComplete经常调用

I have this code:

$( document ).ajaxComplete(function( event, xhr, settings ) {
    console.log('test');
});

I opened the chrome network tab and I can see only one entry (status 200).

But the console displays:

(28) test

Why is it executed this often?

  • 写回答

2条回答 默认 最新

  • weixin_33725272 2015-09-21 12:30
    关注

    The ajaxComplete triggers when any AJAX request is completed, even if it's successfull or not.
    The 200 status code means that your request has gone right, but, as you can read in jQuery docs that callback will fire every time an AJAX request has finished.

    So, you could check what URL is your request redirecting to and handle only the ones that you need.

    Anyway ( just a side note ) I will use the built-in AJAX callback function complete, something like this:

    $.ajax({
        url: url,
        data: { data },
        complete:function(){ 
            console.log('test'); 
        }
    });
    
    评论

报告相同问题?