Rich text field data saved to database

Source: Internet
Author: User
Tags base64

"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,"&gt;"); s = S.replace (/</g,"&lt;"); s = S.replace (/>/g,"&gt;"); s = S.replace (//g,"&nbsp;"); s = S.replace (/\ '/g,"& #39;"); s = S.replace (/\ "/g,"&quot;"); s = S.replace (/\n/g,"<br>");returns;} function html_decode(str) {    vars ="";if(Str.length = =0)return ""; s = str.replace (/&gt;/g,"&"); s = S.replace (/&lt;/g,"<"); s = S.replace (/&gt;/g,">"); s = S.replace (/&nbsp;/g," "); s = S.replace (/& #39;/g,"\ '"); s = S.replace (/&quot;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.