title: How to call a jQuery function after ANY successful Ajax request with MVC partial views
body: <p>I have jQuery code that runs fine when a view is render.  However, I want this same code to run after an Ajax request is successful.  The jQuery was originally performed when the document was ready, but I moved it to it's own function so it can be called.  The function adds a few simple classes to some label elements.  Here is what I have so far:</p>
  
  <pre><code>$(function () {
      afterLoad();
  });
  
  $.ajaxSetup({
      success: function () {
          afterLoad();
      }
  });
  
  function afterLoad() {
      // code to execute
  }
  </code></pre>
  
  <p>This doesn't execute properly after making a simple Ajax request:</p>
  
  <pre><code>$('#ajaxTest').load('&lt;MVC Route&gt;')
  </code></pre>
  
  <p>A partial view is returned just fine, but <code>afterLoad()</code> attempts to run before the partial view is in the DOM.  If I were to execute the same call again <code>afterLoad()</code> does run (on the previous partial view), but then it gets overwritten by the new partial view.</p>
  
  <p>Any thoughts?  Another approach to this would be fine, I'm looking for a was to get the site-level .js file to run after an Ajax request for a partial view.  The master page loads the site.js file, and I would like to execute it's code without reloading the file (since it's already been loaded by the browser).  Also, I don't want to have to force developers to do anything different with their Ajax calls so it needs to work with a simple <code>.load()</code>, etc.</p>