title: JavaScript - failing to submit username, password
body: <p>Failing to submit the username/password using JavaScript but with general web-browser's, while using direct url in address bar it works by inserting the username password manually in the popup. </p>
  
  <p>How to fix it?</p>
  
  <pre><code>&lt;script&gt;
  function make_base_auth(user,password) {
    var tok = user + ':' + password;
    var hash = btoa(tok);
    return "Basic " + hash;
  } // ends
  
  $(document).ready(function() {  
    $.ajax({
      type: "GET",
      url: "http://www.example.be/a/b/c?id=9990",
      dataType: 'xml',
      async: false,
      data: '',
      beforeSend: function(xhr)
      {
        xhr.setRequestHeader('Authorization', make_base_auth("user1", "1234"));
      },
      success: function (data, textStatus, jqXHR){
        console.log(data, textStatus, jqXHR);
      }
    });  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>ERROR from server:</p>
  
  <p><a href="https://i.stack.imgur.com/15JF2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/15JF2.png" alt="enter image description here"></a></p>