title: Ajax: HTTP Basic Auth and authentication cookie
body: <p>I want to store the HTTP basic authentication headerline in an authentication cookie, so that I don't have to deal with the authorisation header in subsequent requests (I'm using jQuery):</p>
  
  <pre><code>authenticate: function(auth) {
      var header = "Basic " + $.base64.encode(auth.username + ":" + auth.password);
      document.cookie = "Authorization: " + header;
      $.ajax({
          type: "GET",
          url: "http://someurl",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: auth.success,
          error: auth.error
      });
  },
  </code></pre>
  
  <p>Whilst this seems to work for the first user who logs in, it doesn't work for any other users within the browser session, because the subsequent authorisation headers are added and not overwritten. I know that one could overwrite a cookie by using the <code>name=value</code> syntax, but this syntax does not apply to the authorization header.</p>
  
  <p>Is there any way to get rid of the old authorization header once a new user logs in?</p>
  
  <p>Any help would be appreciated. Thanks, JeHo</p>