Local Ajax Request / Sencha / Phonegap On Android
Solution 1:
The first thing I do in situations like this is to get rid of the dependency on third party libraries like Sencha or jQuery and go straight to use XHR. There is an issue where making requests from file protocol sometimes returns a status of 0 when it actually is 200. Most libraries have this fixed but you never know. Try this XHR code which should work just great on Android:
var request = new XMLHttpRequest();
request.open("GET", "file:///android_asset/webapp/content/file.html", true);
request.onreadystatechange = function(){
if (request.readyState == 4) {
if (request.status == 200 || request.status == 0) {
console.log("response " + request.responseText);
}
}
}
request.send();
Solution 2:
I'm not sure this totally meets your requirements but have a look at this Phonegap Android plugin collection. It includes plugins for uploading and downloading content for PhoneGap on Android.
Solution 3:
Which version of Sencha Touch are you using? As Simon pointed out, many libs report a failure when encountering a response code of 0, Sencha Touch fixed this as of 2.0.0
Second, try removing the file:///android_asset/webapp/ part of the ULR, a relative url to your content directory should work just fine, and alleviate any OS detection switching you might be doing to arrive at that path.
Ext.Ajax.request({
url: 'content/file.html',
success: function(response, opts) {
console.log('response ' + response.responseText);
}
failure: function(response, opts) {
console.log('response ' + response.responseText);
}
});
Post a Comment for "Local Ajax Request / Sencha / Phonegap On Android"