如果你通过一些富文本web编辑器ueditor编辑文本,存储到数据库中,在通过接口访问,并且作为html显示,则需要将html放入json中~
ueditor编辑
得到一些富文本格式的数据
存储数据库
在存储数据库之前,需要进行一系列格式转化~
http://www.thorntech.com/2012/07/4-things-you-must-do-when-putting-html-in-json/
1.Escape quotation marks used around HTML attributes like so <img src=\"someimage.png\"/>
2.Escape the forward slash in HTML end tags. <div>Hello World!<\/div>. This is an ancient artifact of an old HTML spec that didn’t want html parsers to get confused when putting strings in a <SCRIPT> tag. For some reason, today’s browsers still like it.
3.This one was totally bizarre. You should include a space between the tag name and the slash on self closing tags. I have no idea why this is, but on MOST modern browsers, if you try using javascript to append a <li> tag as a child of an unordered list that is formatted like so: <ul/>, it won’t work. It gets added to the DOM after the ul tag. But, if the code looks like this: <ul /> (notice the space after the /), everything works fine. Very strange indeed.
4.Be sure to encode any quotation marks that might be included in (bad) HTML content. This is the only thing that would really break the JSON by accidentally terminating the string early. Any " characters should be encoded as " if it is meant to be included as HTML content.
返回json数据,插入html
document.getElementById("article").innerHTML=data.item;
通过jquery方法即可