title: How to mock an ajax response
body: <p>How can one mock an ajax response?</p>
  
  <p><a href="https://stackoverflow.com/a/13915248/1032531">https://stackoverflow.com/a/13915248/1032531</a> provides a link to an answer but the link is broken.</p>
  
  <p><a href="https://stackoverflow.com/a/29680013/1032531">https://stackoverflow.com/a/29680013/1032531</a> provides the following answer but it errors with <code>$.ajax is not a function</code>.  <a href="https://jsfiddle.net/bdw0gfan/" rel="nofollow noreferrer">https://jsfiddle.net/bdw0gfan/</a></p>
  
  <pre><code> function ajax_response(response) {
     var deferred = $.Deferred().resolve(response);
     return deferred.promise();
   }
   $(function() {
  
     $.ajax = ajax_response([1, 2, 3]);
     $.ajax('GET', 'some/url/i/fancy').done(function(data) {
       console.log(data); // [1, 2, 3]
     });
   });
  </code></pre>