title: Laravel auth AJAX no popup
body: <p>Ive been going through this <a href="http://code.tutsplus.com/tutorials/laravel-4-a-start-at-a-restful-api-updated--net-29785" rel="nofollow">tutorial</a></p>
  
  <p>Everything works fine from a terminal cURL request but I get a popup for authentication when using jQuery. Is there a way to prevent this popup and pass the login credentials from jQuery to the API? How exactly does --user work from terminal and how do I "simulate" this from jQuery?</p>
  
  <p>Terminal:</p>
  
  <pre><code>$ curl --user username:password http://localhost/api/v1/email
  {"error":false,"authEmail":"me@localhost","message":"request success"}
  </code></pre>
  
  <p>Laravel controller method:</p>
  
  <pre><code>public function index() {
      return Response::json(array(
          'error' =&gt; false,
          'authEmail' =&gt; Auth::user()-&gt;email,
          'message' =&gt; 'request success'), 200);
  }
  </code></pre>
  
  <p>Laravel filter:</p>
  
  <pre><code>Route::filter('auth.basic', function() {
  return Auth::basic('username');
  });
  </code></pre>
  
  <p>Laravel route:</p>
  
  <pre><code>Route::group(array('prefix' =&gt; 'api/v1', 'before' =&gt; 'auth.basic'), function() {
  Route::resource('email', 'EmailController');
  });
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>(function($) {
  $(document).ready(function() {
      $.ajax({
          url: 'http://localhost/api/v1/email',
          type: 'GET',
          dataType: 'json',
          data: {
              username: 'username',
              password: 'password'
          }
      }).complete(function(data) {
          console.log(data.responseJSON);
      });
  });
  })(jQuery);
  </code></pre>