Reputation: 207
I am writing an Android app using Cordova 3.4.0
.
In the app I make the following ajax request using jquery...
$.ajax ({
url: 'http://www.[mydomain].com/api/v1',
type: 'GET',
username: id,
password: pwd,
xhrFields: {
withCredentials: true
},
})
.done (function (response) {
doSomethng();
})
.fail (function (response) {
console.log(response);
});
On Android 4.4.x
the request works as expected, however on Android 4.3
(both emulator and device) it fails and the following is logged to the console...
readystate: 4
status: 404
statusText: "error"
I have <access origin="*" />
in the config.xml
and
<uses-permission android:name="android.permission.INTERNET" />
in the AndroidManifest.xml. I can also confirm that the request is not making it to my web service and nothing is logged on that end.
I am at a loss as to what might be blocking the request. I know that the WebView component is different in 4.4.x
than in previous versions but I am not sure if that has anything to do with it. Any help would be appreciated.
Upvotes: 3
Views: 1918
Reputation: 207
I have found the solution. For anyone running into the same issue do this...
Replace
$.ajax ({
url: 'http://www.[mydomain].com/api/v1',
type: 'GET',
username: id,
password: pwd,
xhrFields: {
withCredentials: true
}
})
with
$.ajax ({
url: 'http://www.messagefund.com/webresources/v1',
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(id + ':' + pwd));
},
type: 'GET'
})
Confirmed that this works in iOS 6.1/7.0/7.1, Android 4.3.x, 4.4.x and Windows Phone 8.
Upvotes: 1