[ 1 post ]

John Bonham

  • Username: John Bonham
  • Joined: Thu May 05, 2011 10:48 am
  • Posts: 38
  • Offline
  • Profile
Tags:

parse JSON in global completeEvent subscriber

Post Posted: Sat Jun 23, 2012 1:45 am
+0-
I want to parse a response string and save it as JSON like the follows:
Code:
YAHOO.util.Connect.completeEvent.subscribe(function(eventType, args) {
      args = args || [];

      var o = args.length ? args[0] : {};
      var responseText = o.conn.responseText;

      if (responseText) {
        try {
          responseText = lang.JSON.parse(responseText);
        } catch (e) {
          responseText = {};
        }
      } else {
        responseText = {};
      }

      o.conn.responseText = responseText;   // the problem is here
    });

But unfortunately when I save 'responseText' variable in o.conn.responseText I don't get a parsed JSON object, so in success callback function I have to do JSON.parse again;
Code:
success: function (o) {
   var r = lang.JSON.parse(o.responseText);

What's wrong in my code above? I want to get parsed JSON object in success callback function. Is it possible?
  [ 1 post ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum