I'm using PhoneGap to build an Android app. Using either jQuery or Zepto, I'm able to make calls to the website APIs using the $.ajax call. However, when the website returns a 401 (unauthorized) response, there seems to be no callback from the ajax call - none of "success", "error", or "complete" get called.
Note that the same code works fine when the response is 200 or 500.
I'm using Zepto 1.0rc1 and/or jQuery 1.7.2 with PhoneGap 1.6.1 .
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$('#button').on('touchstart', function() {
console.log("UPLOAD --- ");
$.ajax({
url: 'https://mywebsite/api/v1.0/test/?ts=' + new Date().getTime(),
type: 'GET',
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth('username', 'password'));
},
success: function(data, status, xhr) {
console.log("AJAX: SUCCESS: " + data);
$('h1').text("AJAX!!");
},
error: function(xhr, errortype, error) {
console.log("AJAX: FAIL: " + errortype + " - " + error);
$('h1').text("AJAX FAIL");
},
complete: function() {
console.log("--- Complete");
}
});
return false;
});