XHR - null response text/data but status code of 200.
I am experiencing the exact same issue as two other people on this board. I keep getting back a null value from a POST request.
even if i send no data to the server, the server will always return something.
I have tried stringify-ing the json object, building the json object at different points, and sending it any way i can think of under the sun.
i am getting a http status code of 200 but no data. i know this server works as i have tested it xcode, objC code and in my browser.
I've followed everything verbatim from examples and i keep getting null data back on a POST.
var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','some url');
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
//ERROR
xhr.onerror = function(e) {
alert("ERROR " + e.error);
Titanium.API.info("some error");
};
//SUCCESS
xhr.onload = function() {
//callback(JSON.parse(this.responseText));
Titanium.API.info(this.responseText);
Titanium.API.info(this.status);
};
var temp = {};
temp.method ="user.login";
temp.username="admin";
temp.password="red99";
xhr.send(temp);
I'm the third person to post about this issue in the last few days or so. seems like something isn't quite right there.
im using version 1.2.1
6 Answers
-
I hesitate to point out something so obvious, but the parse code above is on a comment line…
regards,
JH
-
Just for arguments sake… i did the following where you are suggesting the parse code should be (commented out on purpose):
Titanium.API.info(this.responseText);
Titanium.API.info(JSON.stringify(this.responseText));
Titanium.API.info(JSON.parse(this.responseText));i got:
[INFO] <null>
[INFO] null
[INFO] <null>i receive text back from the server, i should only need to parse if i wish to handle the JSON text as an object. at this point i would be happy to see any response ….
-
Even I am facing the same issue with only one exception. When I try to display the response using alert then it correctly shows the response sent by server. Even you can try alerting it. But whenever I parse the JSON response or do anything else it always gives a null value.
-
I'm having the same problem. If you send with 'POST' apache doesn't see the request, but if you use GET, the servers sees the request correctly and handles it correctly.
I'm using the latest TI.SDK 1.3.0Any ideas?
-
I've got same issue (answer from http after a POST request) if the answer contains non UTF8 characters !
So be sure that's your answer is UTF8 encoded -
I think I found a possible solution to this.
I spent 4h today trying to solve this issue.
Here is what I found so far:- If you :
and then try to send that withvar jData = JSON.stringify({'a':'content'});
You will get <NULL> from the serverxhr.send(jData);
But, if you try:
Then you get a response from the server with anything you wanted back.xhr.send({'a':'content'});
Not sure why that is, but that's what I found.
- If you :