Run callback after Views exposed filter AJAX I feel like I'm doing something really wrong here. I have a View block which has an exposed filter. Since it is in a block I have to use Ajax. I'm trying to run some JS on the views result but can't get anything to happen when the ajax call completes. 

To try and keep this as simple as possible I have created a test.js file with only the following code:

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


I add this with my theme's template.php file but when I filter my view and the results update with ajax, this code does not seem to run. I can't work out why not.

EDIT: I managed to get this to work by moving the code inside my_view.tpl.php but I'd be keen to know why it doesn't work in an external file.
JS events need to be bound when the document is ready. Drupal handles this for you if you use behaviors:

(function ($) {
  Drupal.behaviors.myModule = {
    attach: function(context, settings) {
      $(document).once('mymodule-ajax').ajaxComplete(function (e, xhr, settings) {
      // ...
      });  
    }
  }
})(jQuery);