1

I have a normal http get Ajax call that returns html pre formatted string: '\u000a\u0009\u0009\u0009\u0009\u000a\u0009#07\/04\/2014#\u000a'

I am trying to set this value in pre tag.

HTML: <pre id="preContainer"></pre>

JS: var container = document.getElementById('preContainer');

Work if I pass it in code hardcode value:

container.innerHTML = '\u000a\u0009\u0009\u0009\u0009\u000a\u0009#07\/04\/2014#\u000a';

But do not work if I pass directly the ajax returned object (Angular JS GET Call):

httpFactory.getHTML(..id..).success(function (emailHTML, status) {

            var container = document.getElementById('preContainer');
            container.innerHTML = emailHTML;                
        });

Both the hardcode value and emailHTML value are exactly same. But in later it's not formatting in PRE tag. Any idea Why ?

2 Answers 2

0

My guess is they are not exactly the same, but what ever you're looking at to see the value (like chrome tools or w/e) is just showing it encoded or w/e. (If they were exactly the same you'd have the same result)

Can you just encode the output again before putting into the innerHTML tag?

container.innerHtml = encodeHoweverYouEncode(emailHTML);

(That's probably not how you want it encoded, but use w/e encodes your value there)

1
  • Hi Kyle - When i am logging just after http call using console.log in chrome console window it's showing as a string but when i am copying and pasting again in console window its showing as formatted. Jul 4, 2014 at 20:07
0

I just tried jquery Get call and pre tag is rendering HTML fine. Somehow its not working with Angular JS http call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.