Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Can't use XMLHttpRequest?


Why can't XMLHttpRequest be used anymore (instead of Titanium.Network.HTTPClient)? It was possible in previous versions (at least on v. 0.8.x).

I can't use Titanium.Network.HTTPClient because… it just doesn't work (well)…

— asked April 14th 2010 by Mathieu Scialom
  • xmlhttprequest

3 Answers

  • Hello !

    I haven't had unresolved problems with the HTTPClient yet. Could you explain more about the issues you encountered with this object ?

    Best regards

    Iiii|; )

    — answered April 15th 2010 by akram chakchouk
  • The problems are not with Titanium.Network.HTTPClient itself but with the response we get, in the form of a Titanium.XML.DOMDocument object.

    As you may know, Titanium.XML.DOMDocument has bugs in the last version (1.2) that make it unusable.

    For example, myDoc.getElementsByTagName("myName")[i] doesn't work and have to be replaced by myDoc.getElementsByTagName("myName").item(i). I use some libraries that extensively use myDoc.getElementsByTagName("myName")[i] and I had to change all occurrences of it…

    Another example is performance issues. I used to use some libraries to convert XML SOAP documents into JSON objects. When I was using v. 0.8.x, I used XMLHttpRequest, get the XML response and convert it to JSON using those libraries. It was almost instantaneous.
    Now that we can't use XMLHttpRequest anymore and have to use Titanium.Network.HTTPClient instead, the conversion from Titanium.XML.DOMDocument to JSON takes DOZEN of MINUTES… on my Core2Duo MacBook! And for some of them, it takes several HOURS!

    I tried with several libraries and it was this slow for ALL of them.

    Maybe the bug with myDoc.getElementsByTagName and these performances issues are linked together…

    So, Titanium.Network.HTTPClient can't be used as long as all the problems Titanium.XML.DOMDocument are solved.
    That's why I would like to use the "regular" XMLHttpRequest object.

    — answered April 16th 2010 by Mathieu Scialom
  • I 100% agree. We should be able to use the xmlhttprequest objects.

    — answered March 15th 2011 by Mark Richardson
    1 Comment
    • If you need XML back, you can use the standard HTTPClient and read the results of responseXML (instead of responseText)

      You can then pop this in to a doc model using var doc = this.responseXML.documentElement;

      See the xml_rss.js demo in KitchenSink.

      — commented March 15th 2011 by Kosso
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.