【问题标题】:Issues with posting ajax data in php7在 php7 中发布 ajax 数据的问题
【发布时间】:2019-01-07 13:00:29
【问题描述】:

我在页面上的 POST 数据有问题,它在 chrome 和 Firefox 下工作,但在 IE11 上却异常不工作。事实很简单,如果我们对全局变量$_POST 进行var_dump() php 端的全局变量$_POST 通过ajax 发送变量为null(php 的版本是php7 .1.18),但在 php5.3 服务器上(旧服务器可以正常工作)。

<?php

echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
<!DOCTYPE html   PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR">
<head>
    <script   src="https://code.jquery.com/jquery-1.6.2.js" ></script>

</head>
<body>
<form id="form_ses10_rech" name="form_ses10_rech" action="index.phpp......." method="post">
    <input type="text" name="nom" value="">
    <input type="text" name="prenom" value="">
    <input type="submit" name="subm" value="Envoyer">
</form>


<script>
    $(document).ready(function(){
        $('#form_ses10_rech').submit(function(e){
           // e.preventDefault();
            $.ajax({
                url: 'test.php',
                type: 'POST',
                data: jQuery('#form_ses10_rech').serialize(),
                success: function (data) {
                    console.log(data);
                },
                error: function (error) {
                    console.log(error);
                }
            });
        });
    });

</script>
</body>
</html>

你知道问题所在吗?

谢谢

【问题讨论】:

  • 删除评论 // e.preventDefault();

标签: php jquery internet-explorer-11 php-7.1


【解决方案1】:

您提供的代码是正确的。在 Firefox、chrome 和 IE ( 11.0.75/KB4339093 ) 上对其进行了测试,但无法重现您的问题 - $_POST 对我来说看起来不错

您可以发布您的请求标头吗?

我猜问题不在你的代码中

【讨论】:

    【解决方案2】:

    如何在应用程序的控制器中发布请求标头..就像

    public function ajaxController(Request $request){
    
    var_dump($request); //  it is null
    var_dump($_POST); // it is null
    
    }
    

    测试到现在,我在 apache 中看到了 Keepalive 配置。当保持活动为 5 秒时,我在 5 秒内工作,如果它在 10 秒内工作,它会在刷新页面后在 10 秒内工作,但继续说它不起作用.. 如果 11 秒 .... 请求为空并且没有帖子...我们被阻止了

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2020-04-03
      • 2018-12-12
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 2021-03-27
      相关资源
      最近更新 更多