XHR null response

You must Login before you can answer or comment on any questions.

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

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);
};

I'm happy to report that it was Drupal's fault not Titanium.

Some JSON encoding issues in json_server-2.0-alpha2

— answered 3 years ago by Steve Liddell
answer permalink
2 Comments
  • and I must thank 'aw2xcd' on titanium irc for helping me isolate the issue. cheers!

    — commented 3 years ago 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 3 years ago by Ari Edelson

Your Answer

Think you can help? Login to answer this question!