lemonSkip
lemonSkip

Reputation: 54

Titanium xhr events not firing

I have been trying to get a simple xhr request to work but for some unknown reasons nothing happens, not even the onerror function fires off.

        var xhr = Ti.Network.createHTTPClient();
    xhr.onload = function() {
        Titanium.API.log('Success');
    }
    xhr.onerror = function() {
        Titanium.API.log('Error');
    }

    xhr.open("GET","http://www.google.com/");
    xhr.send();

I have tried this with a new created project and still no luck. Using little snitch I noticed that a connection is made by the app to the given url ... but still nothing fires off.

What am I missing?

Also I'm developing on an iPhone Simulator.

Upvotes: 0

Views: 971

Answers (1)

Craig
Craig

Reputation: 2193

I don't think there's anything wrong with the XHR request - the Titanium.API.log function takes two arguments, but you're only giving it one, so it's probably just not printing to the console. The Titanium documentation is down at the moment so I can't link you to the correct API, but if you change your code to use Ti.API.info, for example, you should see something printed. This works for me:

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
    Titanium.API.info('Success');
}
xhr.onerror = function() {
    Titanium.API.info('Error');
}

xhr.open("GET","http://www.google.com/");
xhr.send();

Upvotes: 2

Related Questions