如何在phonegap ap中通过http身份验证从Web服务器获取数据? 我试过(使用Dom 7):
$$.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);
}
})

和
$$.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);
}
})

但我回复了statusCode = 401。