首页 >社区问答列表 >为什么我这表单提交加空格后,提交值就为空?

为什么我这表单提交加空格后,提交值就为空?

$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);  
                            }  
                        }  
                    });  
                });  
          
});

前端代码

网址:https://t.iaozi.com/ly/