$txt = $_POST["txt"];
if(empty($txt)){
$data="内容不能为空";
echo json_encode($data);
die;
}后端代码
<script>
layui.use('layedit', function(){
var layedit = layui.layedit;
var ly = layedit.build('txt'); //建立编辑器
$("#add").click(function() {
var txt = layedit.getContent(ly);
$.ajax({
type: "POST",
url: "comment.php",
data: "txt=" + txt,
success: function(data) {
data = JSON.parse(data);
if (data.msg == 2) {
$("#message").show().html("发表成功!").fadeOut(1000);
$("#txt").val("");
} else {
$("#message").show().html(data).fadeOut(1000);
}
}
});
});
});前端代码
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
data: "txt=" + txt 改成这样 data: {txt:txt}