empty JSON variables after AJAX request
Hello,
I'm just programming an AJAX Request:
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var json = JSON.parse(this.responseText);
var jsnrows = json.rows;
Titanium.API.log("Test");
};
xhr.open("GET", "192.168.1.105/ajax/pdo.php");
xhr.send();
The php file really returns the JSON Files. I checked this already. But there is no entry in the console. What's my mistake?
Thanks!
5 Answers
-
Accepted Answer
I ran into an issue this week where I was 100% positive that I successfully returning JSON, but the
responseText
was returned as null. I finally discovered that using non-ascii characters was causing the problem. I'm betting that this is your issue too. You will need to handle unicode special characters prior to sending. One possibility is to use the hex code prior to sending.See http://developer.appcelerator.com/question/1311/special-characters-like—- and http://www.utf8-chartable.de/.
-
Try
Titanium.API.info("Test");
-
Thank you for your answer!
It also doesn't work. My guess is that it doesn't work, cause the JSON isn't correctly received. So there is no entry in the console.
Maybe you have another idea?
-
Does it help to add "http://" to your URL in your GET request?
-
I ran into a similar issue yesterday. I was able to figure out my problem by examining the responseText.
Try adding
Titanium.API.info(this.responseText);
before you parse it to see what you're trying to parse.