开发者

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.


  1. Convert HTML fragments to html entities at server side (if you are using PHP use htmlentities() function)
  2. Send JSON output from server
  3. At client-side do json.yourHTMLEntityEncodedString.replace(/&amp;/, '&').replace(/&gt;/, '>').replace(/&lt;/, '<')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜