Page 1 of 1

JSON Encoded HTML Fails

Posted: Wed Jun 08, 2011 4:50 pm
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...
news_text.appendChild(document.createTextNode(feed[0]['message']));


My encoded array outputs...

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

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

$data[0][$k]['message'] = '<a href="../u/' .$r['feedusername']. '">' .ucwords($r['feedfirstname'].' '.$r['feedlastname']). '</a> has updated ' .($r['gender'] == 1 ? 'his': 'her');

Re: JSON Encoded HTML Fails

Posted: Wed Jun 08, 2011 5:01 pm
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.

Re: JSON Encoded HTML Fails

Posted: Wed Jun 08, 2011 5:03 pm
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.