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
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