dongtang3155 2019-05-12 06:17
浏览 240
已采纳

var_dump() - $ _POST变量在通过jQuery的$ .post()方法发布字符串时显示空数组

Let's put examples to demonstrate my problem:

index.html:

<!doctype html>

<html>

  <head>

    <title>Testing XHR</title>

    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

  </head>

  <body>

    <script>

      $(function()
      {
        const test = "This is a test text.";
        $.post("test.php", {data: test}, function()
        {
          console.log(test);
        });
      });

    </script>

  </body>

</html>

test.php:

<?php
var_dump($_POST);

So, when I load index.html, it completes $.post() request successfully. I have checked it via Chrome's "Inspect" option, under "Network" tab. But when I load test.php, it shows empty string. I have tested it to my local server and a live server, results are the same. What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • douju1997 2019-05-12 06:26
    关注

    console log the response you get from test.php.

    $.post("test.php", {data: test}, function(response)
    {
        console.log(response);
    });
    

    loading the test.php won't show you the post data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?