Titanium Community Questions & Answer Archive

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

XHR null response

HI,

I'm sending a JSON request to a Drupal web service that normally works via javascript in the browser. Yet when I use Titanium on the iPhone I receive a null response.

I've pointed my iPhone/Titanium request to a small script that intercepts my POST data so I can analyse exactly what the server is seeing and it is showing exactly the same as the web version produces.

Which is:

Array
(
    [method] => system.connect
)

So the output to the server seems valid - I'm just not getting back what the web version receives.

my Titanium/JS code looks like the following:

var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function()
{
    Ti.API.info(this.responseData);
    Ti.API.info(this.responseText);
    Ti.API.info(this.responseXML);
    Ti.API.info(this.status);
    Ti.API.info(this.connectionType);
};
xhr.onerror = function()
{
    alert('POST error');
};
xhr.setRequestHeader("Content-Type", "application/json");
xhr.open("POST","http://myserver.tld/services/json");
xhr.setTimeout([20000]);
xhr.send(anon_user_meth);

Many Thanks,

Steve

— asked November 29th 2010 by Steve Liddell
  • iphone
  • json
  • mobile
  • null
  • post
0 Comments

2 Answers

  • try changing all of the "this" to "xhr"

    xhr.onload = function()
    {
        Ti.API.info(xhr.responseData);
        Ti.API.info(xhr.responseText);
        Ti.API.info(xhr.responseXML);
        Ti.API.info(xhr.status);
        Ti.API.info(xhr.connectionType);
    };
    
    — answered November 29th 2010 by Aaron Saunders
    permalink
    1 Comment
    • Unfortunately this is giving the same result. :-/ thanks though.

      — commented November 29th 2010 by Steve Liddell
  • I'm happy to report that it was Drupal's fault not Titanium.

    Some JSON encoding issues in json_server-2.0-alpha2

    — answered November 30th 2010 by Steve Liddell
    permalink
    2 Comments
    • and I must thank 'aw2xcd' on titanium irc for helping me isolate the issue. cheers!

      — commented November 30th 2010 by Steve Liddell
    • Steve-

      I am encountering the exact same problem. Is there any chance you can share how you got around the issues in json_server-2.0-alpha2? I am using that, Services 2 and PHP 5.2.9.

      — commented May 15th 2011 by Ari Edelson
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.