Titanium Community Questions & Answer Archive

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

Debug console output

Say I make an XHR request and get back a HTML fragment (or the whole page), how can I see the unformatted output of that in the console, tags and all.
At the moment it displays formatted output and I need to take a look at what an HTML doc looks like at the device end. Whats a good work around for this?

TIA
Dave

— asked March 17th 2010 by David McL
  • debug
  • html
  • iphone
0 Comments

3 Answers

  • From a stackoverflow post

    function h(s) {
        return s.split('&').join('&').split('<').join('<').split('"').join('"');
    }
    
    — answered March 18th 2010 by David McL
    permalink
    0 Comments
  • I guess you could try a JavaScript equivalent to the PHP function htmlspecialchars

    http://phpjs.org/functions/htmlspecialchars:426

    In fact this whole site in extremely useful for people who know PHP and need a JavaScript equivalent ;)

    http://phpjs.org/

    — answered March 17th 2010 by Kosso
    permalink
    0 Comments
  • Probably the easiest way would be to make a function that might look something like this, and pass the results from your the call into it:

    function dehtml( html ){
      var text = html.replace( /&/g, "&amp;" );
      text = text.replace( /</g, "<" );
      text = text.replace( />/g, ">" );
      return text;
    }
    

    If its used in a lot of places, you might even have this function also call the logging function.

    — answered March 17th 2010 by Allen Firstenberg
    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.