title: Use basic authentication with jQuery and Ajax
body: <p>I am trying to create a basic authentication through the browser, but I can't really get there.</p>
  
  <p>If this script won't be here the browser authentication will take over, but I want to tell the browser that the user is about to make the authentication.</p>
  
  <p>The address should be something like:</p>
  
  <pre><code>http://username:password@server.in.local/
  </code></pre>
  
  <p>I have a form:</p>
  
  <pre><code>&lt;form name="cookieform" id="login" method="post"&gt;
        &lt;input type="text" name="username" id="username" class="text"/&gt;
        &lt;input type="password" name="password" id="password" class="text"/&gt;
        &lt;input type="submit" name="sub" value="Submit" class="page"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And a script:</p>
  
  <pre><code>var username = $("input#username").val();
  var password = $("input#password").val();
  
  function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = Base64.encode(tok);
    return "Basic " + hash;
  }
  $.ajax
    ({
      type: "GET",
      url: "index1.php",
      dataType: 'json',
      async: false,
      data: '{"username": "' + username + '", "password" : "' + password + '"}',
      success: function (){
      alert('Thanks for your comment!');
      }
  });
  </code></pre>