Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12962] Android: XHR request not working on OS 2.x with SDK 3.0.2 GA

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-03-06T01:54:57.000+0000
Affected Version/sRelease 3.0.2
Fix Version/sRelease 3.1.0, 2013 Sprint 05 API, 2013 Sprint 05
ComponentsAndroid
Labelsregression
ReporterDaniel Sefton
AssigneeIngo Muschenetz
Created2013-03-05T19:12:04.000+0000
Updated2014-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();

Comments

  1. Daniel Sefton 2013-03-06

    Tested by QE. Confirmed solution to use baseURL property of setHTML(). See solution provided in description.

JSON Source