Using the jquery form plugin, how do I stop json-encoded html from being escaped
I've got a setup where I use the JQuery Form plugin to submit my forms through ajax, returning a json object from the server (running django, using simplejson.dumps). The json returned is constructed as this:
status: [success/invalid/error] error: [errortext if any] html: [html-text to be inserted]
My problem is that when entering the success function of my ajax call, the html part of the json is escaped so that the results I get are of the type <strong>Hello<\strong>
. I've doublechecked the json string produced by the server, it validates using json-lint and has unescaped html-entities. Any suggestions on how I stop JQuery from escaping my开发者_运维百科 html?
Make sure you're using .html()
to use that response and not .text()
, which will escape it like you're talking about.
- Convert HTML fragments to html entities at server side (if you are using PHP use
htmlentities()
function) - Send JSON output from server
- At client-side do
json.yourHTMLEntityEncodedString.replace(/&/, '&').replace(/>/, '>').replace(/</, '<')
精彩评论