JSON Encoded HTML Fails

JavaScript related questions should go here.
Post Reply
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

JSON Encoded HTML Fails

Post by unemployment »

The HTML code in my array is being appended as

<a href=\"../u/ldgbug\">Sam Sangs</a> has updated her location.

When I want the actual html included on the page. Any idea how I can fix this?

I am using this to generate it...
[syntax=javascript]news_text[i].appendChild(document.createTextNode(feed[0][i]['message']));[/syntax]

My encoded array outputs...

<a href=\"..\/u\/somebug\">Sam Sangs<\/a> has updated her location.

And this php is what generates that array value...

[syntax=php]$data[0][$k]['message'] = '<a href="../u/' .$r['feedusername']. '">' .ucwords($r['feedfirstname'].' '.$r['feedlastname']). '</a> has updated ' .($r['gender'] == 1 ? 'his': 'her');[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: JSON Encoded HTML Fails

Post by jacek »

That's what createTextNode does :?

If you are sending html code via JSON, you are using JSON wrong.

You should send the data only and have JavaScript create the layout.

Also, please make sure you post in the correct sections.
Image
unemployment
Posts: 165
Joined: Fri May 06, 2011 5:02 pm

Re: JSON Encoded HTML Fails

Post by unemployment »

jacek wrote:That's what createTextNode does :?

If you are sending html code via JSON, you are using JSON wrong.

You should send the data only and have JavaScript create the layout.


Hmm ok well that's good to know. I'll just have JS create everything.

jacek wrote:please make sure you post in the correct sections.


Whoops. Sorry. My mind is traveling a mile a minute.
Post Reply