flask UEditor富文本提交数据到后台以及复现到前端页面
来源:互联网 发布:如何用字符串表示json 编辑:程序博客网 时间:2024/05/01 12:06
如下 通过ajax的POST方式将富文本里的内容传到后台:
前端:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <title>完整demo</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor/ueditor.config.js') }}"></script> <script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor/ueditor.all.min.js') }}"> </script> <!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败--> <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文--> <script type="text/javascript" charset="utf-8" src="{{ url_for('static', filename='ueditor/lang/zh-cn/zh-cn.js') }}"></script> <style type="text/css"> div{ width:100%; } </style></head><!--<div>--> <!--<h1>完整demo</h1>--> <!--<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>--><!--</div>--><form name="ueditor" id="ueditor"> <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script> //这是你的富文本容器。id可任意命名</form><button id="submit">subit............</button><p id="l" >{{ post.body }}</p><!--<p>123123121<img src="http://127.0.0.1:5000/static/ueditor/php/upload/image/2017111/191016489453.jpg"--> <!--title="Koala.jpg" alt="Koala.jpg" style="width: 243px; height: 164px;" width="243" height="164"/></p>--><script src="https://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script><script> $(document).ready(function(){ var a = $("#l").text(); $(this).html(a) });var ue = UE.getEditor('editor', { serverUrl: "/upload/" });var ue = UE.getEditor('editor');$("#submit").click(function(){var data = UE.getEditor('editor').getContent();alert("1111111111111111") $.post("/shiyan", { //name:data, //city:"Duckburg" }) });</script></body></html>
然后后台获取: 本文里有涉及到数据库 ,调用并前台显示富文本。
@main.route('/shiyan', methods=['GET', 'POST'])def shiyan(): if request.method == 'POST': # 当以post方式提交数据时 print "-----------1111111111---------------------" print request.form["name"] post = Post(body=request.form["name"]) db.session.add(post) post = Post.query.filter_by(id=2).first_or_404() return render_template('shiyan2.html',post=post)
如此就会在命令行里打印出富文本数据。
在前端复现的时候会出现个问题: 因为是将富文本以html格式存到数据库里面。所以传到前端后,会显示字符而没有html 格式 。所以要在里面添加一个jq语句。将里面的字符获取后,然后再改为html格式。则样式就出现了:
$(document).ready(function(){ var a = $("#l").text(); $("#l").html(a)});
0 0
- flask UEditor富文本提交数据到后台以及复现到前端页面
- kindEditer富文本编辑器从前端到后台完整经验
- 百度ueditor富文本--图片保存路径的配置以及上传到远程服务器
- Flask项目集成富文本编辑器UEditor
- Flask项目集成富文本编辑器UEditor
- 百度富文本编辑器ueditor上传文件到bcs中
- 富文本 ckeditor 的使用及传递到后台与在前端使用
- Django在前台使用富文本model,实现后台能取得到页面富文本框中的值
- 前端页面利用AJAX将数组数据传送到后台
- ajax提交数据到后台
- ueditor富文本编辑器嵌入jsp页面
- JSP页面使用富文本控件ckeditor提交表单数据
- 从前端页面到后台的流程
- Struts2自定义过滤器 + 百度富文本控件UEditor + Smb上传图片到独立服务器
- 百度富文本编辑器ueditor上传文件到对象存储BOS中
- ueditor+requirejs+springMVC+七牛(富文本编辑器图片上传到指定服务器)
- ajax提交数据到后台php接收
- 将grid数据提交到后台保存
- NVIDIA Jetson TX1(3)
- 使用SwipeRefreshLayout实现recycleview下拉刷新上拉加载
- 安卓开发中各种颜色设置
- Debian8 更新源配置
- 当你在浏览器地址栏输入一个URL后回车,将会发生的事情?
- flask UEditor富文本提交数据到后台以及复现到前端页面
- Git 基本原理
- 微信小程序项目结构
- 【Window 硬件】U盘写保护 - 允许从U盘向电脑Copy资料,禁止从电脑向U盘拷贝资料
- VB中DoEvents的用途
- ios学习--正则表达式30分钟入门教程
- centos7下将docker的storage 由loop-lvm 更改为 direct-lvm
- error LNK1104: 无法打开文件“opencv_core249d.lib"
- NVIDIA发布移动超级计算机“Jetson TK1”性能超树莓派