Titanium Community Questions & Answer Archive

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

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!

— asked April 3rd 2010 by Claus Moritz Gräf
  • ajax
0 Comments

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

    — answered April 11th 2010 by JC Yandell
    permalink
    0 Comments
  • Try Titanium.API.info("Test");

    — answered April 3rd 2010 by Don Thorp
    permalink
    0 Comments
  • 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?

    — answered April 4th 2010 by Claus Moritz Gräf
    permalink
    0 Comments
  • Does it help to add "http://" to your URL in your GET request?

    — answered April 7th 2010 by JC Yandell
    permalink
    0 Comments
  • 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.

    — answered April 7th 2010 by JC Yandell
    permalink
    0 Comments
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.