标题:
欢迎使用 wangEditor 富文本编辑器
推荐
不推荐
提交
var E = window.wangEditor;
var editor = new E('#editor');
var $text1 = $('#contents');
editor.customConfig.onchange = function (html) {
// 监控变化,同步更新到 textarea
$text1.val(html)
};
editor.customConfig.debug = true;
editor.customConfig.uploadFileName = 'image'; //上传的文件名
// 或者 var editor = new E( document.getElementById('editor') )
editor.customConfig.uploadImgServer = "/hfback/after/uploads"; // 上传图片到服务器
editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024; //图片的尺寸
editor.customConfig.uploadImgMaxLength = 5; //最多上传多少
editor.customConfig.uploadImgParams = {
type: 'editor' // 属性值会自动进行 encode ,此处无需 encode
};
editor.create();
$text1.val(editor.txt.html())
//点击提交按钮
$(".one").click(addUser)
function addUser() {
var addhelp = {
//要先获取标题 内容
titles: $("#titles").val(),
contents: $("#contents").val(),
recommend: $("input[name='identity']:checked").val()
};
//提交内容到服务器
$.ajax({
url: "/hfback/After/present",
data:addhelp,type: "post",
dataType: "json",
//mgs 是返回的数据存储在mgs
success: function (mgs) {
//弹窗提示
console.dir(mgs)
// 提交是否成功 给个判断
if (mgs["one"] == '1') {
alert('添加成功');
} else {
alert('添加失败')
}
}
})}
后台控制器方法,获取过来的值,插入数据库当中
public function present()
{
$data =Request::only(["titles","contents","recommend"]);
$values = [
'title' => $data['titles'],
'content' => $data['contents'],
'recommend' => $data['recommend'],
'time' => time()
];
$validate = new addition;
if (!$validate->check($values)) {
$this->success(($validate->getError()), '/hfback/after/addition');
}
$aaa = Db::table('hf_help')
->insert($values);
if($aaa == 1){
return json(["one" => 1]);
}else{
return json(["one" => 2]);
}
}