Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17432] iOS: HTTPClient not fire onload onerror when set option async false

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2014-09-05T18:06:39.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsSDK3.3.0
ReporterTadatoshi Hanazaki
AssigneeIngo Muschenetz
Created2014-07-18T15:55:55.000+0000
Updated2017-03-20T22:25:07.000+0000

Description

It's seems to HTTPClient.open doesn't work when set async = false.
var win = Ti.UI.createWindow({backgroundColor:'white'});

var button1 = Ti.UI.createButton({
    title:'GET async=false',
    top:'15%',
});
 
var button2 = Ti.UI.createButton({
    title:'GET async=true',
    top:'30%',
});
 
 
button1.addEventListener('click', function () {

    this.title = 'sending...';

	var onload = function(e) {
		Ti.API.debug('onload responseText='+this.responseText);
		button1.title = 'onload';  
	};

	var onerror = function(e) {
		button1.title = 'onerror';  
	};

	var _xhr = Ti.Network.createHTTPClient({
		onload: onload,
		onerror: onerror,
		cache: false
	});

	var url = 'http://ip.jsontest.com/';
	_xhr.open('GET', url, false);
	_xhr.timeout = 5000;
	_xhr.send();

});

button2.addEventListener('click', function () {

    this.title = 'sending...';

	var onload = function(e) {
		Ti.API.info(String.format('onload e = %s', e||{}));
		Ti.API.debug('onload responseText='+this.responseText);
		button2.title = 'onload';  
	};

	var onerror = function(e) {
		Ti.API.error(String.format('error e = %s', e||{}));
		button2.title = 'onerror';  
	};

	var _xhr = Ti.Network.createHTTPClient({
		onload: onload,
		onerror: onerror,
		cache: false
	});

	var url = 'http://ip.jsontest.com/';

	Ti.API.debug('url = '+url);
	_xhr.open('GET', url, true);
	_xhr.timeout = 5000;
	_xhr.send();

});

win.add( button1 );
win.add( button2 );

win.open();  
Expected Result : when tap both button1 and button2 text should change to "onload" or "onerror". Actual Result: only button2 works. button1 text stays "sending..."

Comments

  1. Shuo Liang 2014-07-31

    Hi, Tested with your code. Can reproduce your problem on SDK 3.3.0.GA. But It works well in SDK 3.2.3GA. I will forward this ticket to our engineer team to get this fixed. Thanks Regards, Shuo
  2. Pedro Enrique 2014-09-05

  3. Lee Morris 2017-03-20

    Closing ticket as duplicate.

JSON Source