php接收不了post 传来的数据?求大神帮忙解决

HTML代码:

<form action="release.php" class="release" method="post">
        <label for="title" class="title_label">标题:<input type="text" class="title_input" id="title" name="title"  placeholder="必填"></label>
        <label for="article" class="article_label">
           文章: <textarea name="article" id="article" cols="30" rows="10" class="article"  placeholder="必填"></textarea>
        </label>
        <div class="res_container">
            <button class="res">发布</button>
        </div>

    </form>

jquery 代码:
 var title_input = "title="+$(".title_input").val();
   var article_input ="article="+ $(".article").val();

$.post("release.php",{
            title:title_input,
            article:article_input
        },function(result){
            $(".load").remove();
            if(1==result)
            {
                alert("已经成功插入");
            }
            else{
                //alert(result);
                console.log(result);
            }
        });
        
        
        

php 代码:

header("Content-Type:text/html;charset=utf-8");
print_r($_POST);
$title=addslashes($_POST['title']);
$article=addslashes($_POST['article']);
//$title="weishenme";
//$article="这篇文章内容为空";
if($title)
    echo "$title ,$article";
else
    echo "找不到变量";
    

chrome 调试结果

Request URL:http://localhost:63342/leaveN...
Request Method:POST
Status Code:200 OK
Remote Address:127.0.0.1:63342
Response Headers
view source
access-control-allow-credentials:true
access-control-allow-headers:accept
access-control-allow-headers:content-type
access-control-allow-headers:origin
access-control-allow-headers:authorization
access-control-allow-origin:http://localhost:63342
content-length:273
Content-Type:text/html;charset=utf-8
server:PhpStorm 10.0.3
vary:origin
X-Powered-By:PHP/5.6.27
Request Headers
view source
Accept:/
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8
Connection:keep-alive
Content-Length:177
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:63342
Origin:http://localhost:63342
Referer:http://localhost:63342/leaveN...
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
view source
view URL encoded
title:title=对方如果突然欢迎您
article:article=啊果然他好久没

阅读 3.5k
5 个回答

看到了,你这边不需要 "title="+,直接:

var title_input = $(".title_input").val();

即可。

 var title_input = $(".title_input").val();
   var article_input =$(".article").val();

下面这两行改一下

var title_input = "title="+$(".title_input").val();
var article_input ="article="+ $(".article").val();

改为

var title_input = $(".title_input").val();
var article_input = $(".article").val();

不知道题主前拼上那一段是处于什么考虑,当然这个可能跟题主遇到的问题无关,题主问题描述的并不是很清楚,是怎么样的输出让题主觉得接收不了post数据呢?

提交到后端的数据有问题,不用在获取的时候加上key=value这样

var title_input = $(".title_input").val();
var article_input = $(".article").val();

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题