Handling HTML strings with JavaScript

I Have built a system that uses a simple templating system to separate the logic from layout, but after I have populated my templates with data on the server I want to send this to javascript on the client so that I can dynamically add the templates and content to the page.

I am having some issues handling HTML in javascript. I tried serializing in PHP and then unserializing in javascript with no luck. If I use json_encode() PHP function this gives me errors. My PHP return is just a simple arraywith HTML as one element.

I have also been looking at JavaScript templating systems as I like the idea of using the server just to process data leaving the client to process layout and templates. But is there a way to copy HTML in JavaScript.

Any help or advice appreciated.

I’ve had luck with this using innerHTML to insert the html and mysql_escape_string() to prevent double and single quotes from causing a problem.

mysql_escape_string() is not a suitable way to prepare a javascript string. json_encode() is perfect though.

I am having issues using json_encode(). Actually, I have opted to just generate json from a php array and send this to the browser and once javascript has picked this up implement a javascript based templating system. Problem now is how do I pull an external HTML template file into javascript as an object?

I have been looking at the jquery clone() method.