phonegap/cordova http basic auth
<p>How can I get data from web server with http authentication in phonegap ap?
I tried (use Dom 7):</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$$.ajax({
  url: 'http://@api.mysite.com/api/json',
  method: 'GET',
  dataType: 'json',
  xhrFields: { withCredentials: true },
  beforeSend: function (xhr){
    xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ":" + password));
  },
  success: function (data, status, xhr) {
    console.log(arguments);
  },
  error: function (xhr, status) {
    console.log(arguments);
  }
})</code></pre>
</div>
</div>
</p>

<p>and</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$$.ajax({
  url: 'http://' + username + ':' + password + '@api.mysite.com/api/json',
  method: 'GET',
  dataType: 'json',
  xhrFields: { withCredentials: true },
  success: function (data, status, xhr) {
    console.log(arguments);
  },
  error: function (xhr, status) {
    console.log(arguments);
  }
})</code></pre>
</div>
</div>
</p>

<p>but i have statusCode = 401 in response.</p>