為什麼我這表單提交加空格後,提交值就為空?
**推广网
**推广网 2018-09-13 17:57:59
0
2
1143
$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/#

**推广网
**推广网

中国推广网:http://bbs.iaozi.com

全部回覆(1)
Summer

data:  "txt=" + txt   改為這樣 data: {txt:txt}

#
  • 回覆 √ ,謝謝
    **推广网 作者 2018-09-14 09:00:43
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!