"Rich text field data saved to database", this title feeling is not clear enough. Had to repeat again, the front-end use of bootstrap WYSIWYG rich text components, and then just do not know how to save the picture, the image data submitted to the database, the front end can not be displayed.
See Jquery.base64.js today, vaguely know the solution.
Often inadvertently found articles are deducted to a variety of sites above, very hateful!
Then life where not reptile, crawler please mark Http://blog.csdn.net/qing_gee
Emulate Yan, see not yin and internal introspection also!
General Practice
function html_encode(str) { vars ="";if(Str.length = =0)return ""; s = str.replace (/&/g,">"); s = S.replace (/</g,"<"); s = S.replace (/>/g,">"); s = S.replace (//g," "); s = S.replace (/\ '/g,"& #39;"); s = S.replace (/\ "/g,"""); s = S.replace (/\n/g,"<br>");returns;} function html_decode(str) { vars ="";if(Str.length = =0)return ""; s = str.replace (/>/g,"&"); s = S.replace (/</g,"<"); s = S.replace (/>/g,">"); s = S.replace (/ /g," "); s = S.replace (/& #39;/g,"\ '"); s = S.replace (/"/g,"\""); s = S.replace (/<br>/g,"\ n");returns;}
In general, HTML data is encoded and decoded using the two methods above, but there is nothing to save the image.
Jquery.base64
This plugin is very useful, and it provides a index.html example, after testing to completely solve the picture data preservation and Chinese problems.
The first step is to introduce jquery.base64.js.
<script type="text/javascript" src="${ctx}/components/jquery/jquery.base64.js"></script>
Step two, encode data submission Form
var $this = $(this);var"<input type=‘hidden‘ name=‘" + $this.attr("name""‘ value=‘" + $.base64.btoa($this"‘ />";$form.append(editor);
The third step, decoding the data display
$(‘#editor‘true));
1. database field description
longtext not NULL COMMENT ' item description ',
2. $.base64.utf8encode = true; set UTF encoding to make sure Chinese is not garbled.
Show
Epilogue : If you need more code examples, see how to encapsulate the rich Text Editor in form form Bootstrap WYSIWYG to jfinal pass parameters
Copyright notice: This site blog is qing_gee original article, if you can see on the top, unless you want to comment, then do not too slow yo, oh haha, happy reading!
Rich text field data saved to database