search

Home  >  Q&A  >  body text

Why is the submitted value empty after I add spaces to the form submission?

$txt = $_POST["txt"];  
if(empty($txt)){  
   $data="内容不能为空";
   echo json_encode($data);     
   die;
}

Back-end code



##

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

Front-end code


Website:

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

**推广网**推广网2290 days ago1213

reply all(2)I'll reply

  • Summer

    Summer2018-09-13 19:56:36

    data: "txt=" + txt Change to this data: {txt:txt}

    reply
    0
  • **推广网

    √ , thank you

    **推广网 · 2018-09-14 09:00:43
  • Cancelreply