I have a phonegap app w/ jQuery 1.9.1 Worked great as long as the username doesn\'t have \'@\' symbol in it (like in email addresses). It only fails on iOS.
I suspec
Try wrapping encodeURIComponent() before base64 encoding.
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization",
"Basic " + $.base64.encode(encodeURIComponent(this.username + ":" + this.password)));
},
I would bet the problem is not using a contentType : "application/x-www-form-urlencoded"
.
Anyway, you should definitely debug your Webview against a real device, to look for xhr errors on the Safari console. If you are not familiar with Safari remote debugging, it's easy:
When base64encoded text is UNencoded on the other end, it still looks like (as you said), user@domain:password@blah.domain.com
Try having a function like this:
var getAuthToken = function (user, pass) {
var token = "";
if (user) {
token = token + encodeURIComponent(user);
}
if (pass) {
token = token + ":" + encodeURIComponent(pass);
}
token = $.base64.encode(token);
return "Basic " + token;
};
Then just change your code slightly:
xhr.setRequestHeader("Authorization", getAuthToken(this.username, this.password));