title: Delphi Datasnap testing with javascript client
body: <p>Trying to test a new datasnap server with a simple javascript client. It works up until i turn on authorization on the server then i keep getting 401 errors and the onAuthorization event is not passing in any usernames or passwords they are always blank.</p>
  
  <pre><code>$(document).ready(function(e) {
  
  var jsonStr = {
  "ContactName": "smith, anthony",
  "FirstName": "anthony",
  "LastName": "smith"
    };
  
  
    function make_base_auth(user, password) {
  var tok = user + ':' + password;
  var hash = btoa(tok);
  return "Basic " + hash;
    }
  
    var userName = "admin";
    var password = "admin";
    var authStr = convertStringToBase64(userName + ":" + password);
    var authObj = '{"authentication":authStr}';
  
  
    $.ajax({
  url: "http://127.0.0.1:8086/api/services/Customers/RegisterCustomer",
  headers: {
    "Authorization": make_base_auth(userName, password)
  },
  beforeSend: function(xhr) {
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Accept", "application/json");
    //xhr.setRequestHeader ("Authorization", make_base_auth (userName, password)); 
  },
  crossDomain: true,
  type: "POST",
  dataType: "json",
  data: JSON.stringify(jsonStr),
  
  success: function(result, status, jqXHR) {
    $("preerror").text("IT WORKED");
    var jsonStr = result;
    var jsonObj = JSON.parse(jsonStr);
    var jsonPretty = JSON.stringify(jsonObj, null, '\t');
  
    $("pre").text(jsonPretty);
  },
  error(jqXHR, textStatus, errorThrown) {
    $("pre").text("FAIL");
  }
    });
  
  });
  </code></pre>