title: Jquery authentication error
body: <p>Consider the following code:</p>
  
  <pre><code>var jsonData1 = $.ajax({
  
        url: 'http://'+domainName+':9898/jolokia/read/*',
        dataType:"json",
        crossDomain: true,
        beforeSend: function(xhr){
            var username= '*';
            var password= '*';
              xhr.setRequestHeader("Authorization",
                  "Basic " + btoa(username + ":" + password));
  
          },
        async: false
        }).responseText;
  
    var parsed1 = JSON.parse(jsonData1);
  </code></pre>
  
  <p>Here when I directly access the url, it asks for a username and password, which when given shows the value. 
  But when I do it through an ajax call, it throws this error:</p>
  
  <pre><code>Failed to load resource: the server responded with a status of 401 (Unauthorized)
  jquery.min.js:5 XMLHttpRequest cannot load     http://10.91.240.21:9898/jolokia/read/* No     'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 401.
   (index):1 Uncaught SyntaxError: Unexpected token u
  </code></pre>
  
  <p><strong>TRY 2:</strong></p>
  
  <pre><code>      var jsonData2 = $.ajax({
          type:'GET',
        url: 'http://'+domainName+':9898/jolokia/read/*',
        dataType:"jsonp",
        crossDomain: true,
        data: {username: '*',password: '*'},
        async: false
        }).responseText;
  
    var parsed2 = JSON.parse(jsonData2);
  </code></pre>
  
  <p>I tried using json p.
  The unauthorized code got resolved. It is showing status OK. But now this error comes</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token u
  </code></pre>