[TIMOB-12962] Android: XHR request not working on OS 2.x with SDK 3.0.2 GA
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-03-06T01:54:57.000+0000 |
Affected Version/s | Release 3.0.2 |
Fix Version/s | Release 3.1.0, 2013 Sprint 05 API, 2013 Sprint 05 |
Components | Android |
Labels | regression |
Reporter | Daniel Sefton |
Assignee | Ingo Muschenetz |
Created | 2013-03-05T19:12:04.000+0000 |
Updated | 2014-06-19T12:44:09.000+0000 |
Description
*Problem description*
Run the following test case on Android OS 2.x and SDK 3.0.2 GA to find that the XHR request returns "Web page not available". It works fine on later OS versions and SDK 3.0 GA.
*Test case*
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff',
exitOnClose : false
});
var xhr = Titanium.Network.createHTTPClient({
validatesSecureCertificate : false,
enableKeepAlive : true,
timeout : 10000
});
xhr.onerror = function(e) {
};
xhr.onload = function() {
var webview = Titanium.UI.createWebView({
html : this.responseText
});
win1.add(webview);
};
xhr.open('GET', "http://google.com/");
xhr.send();
win1.open();
*Solution (baseURL)*
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff',
exitOnClose : false
});
var xhr = Titanium.Network.createHTTPClient({
validatesSecureCertificate : false,
enableKeepAlive : true,
timeout : 10000
});
xhr.onerror = function(e) {
};
var baseURL = "http://google.com/";
xhr.onload = function() {
var webview = Titanium.UI.createWebView();
webview.setHtml(this.responseText, {
baseURL : baseURL
});
win1.add(webview);
};
xhr.open('GET', baseURL);
xhr.send();
win1.open();
Tested by QE. Confirmed solution to use baseURL property of setHTML(). See solution provided in description.