dongqiao1151 2018-07-17 15:52
浏览 62

浏览器不响应标题重定向

please help... i am new to php. Thanks

php1 is to send a data ('1234') via method Post to php2. php2 is supposed to redirect using Header Location to php3 with a data ('invalid').

Developer Tools of Chrome indicate that everything went well (Post data sent and received. Get data sent and received). Somehow, the browser does not response and stay at php1. I have tried Safari and Firefox. No response. Would be really grateful if you could advise. Thanks

The 3 php files are:

php1

<?php 
session_start();
$M = '';
if (isset($_GET['m'])) {
    $M = $_GET['m'];
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#send').click(function () {
      var str = '1234';
      $.post('php2.php',
        {
        email: str
        },
        function (data, status) {
        }
      );
    });
});
</script>
</head>
<body>
<div>
<button id="send">SEND</button>
<br>
<?php echo $M; ?>
</div>
</body>
</html>

php2

<?php
session_start();
ob_start();
error_reporting(E_ALL);
if (!empty($_POST)){
    $Email = $_POST['email'];
    if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
        header('Location: php3.php?m=invalid');
        exit();
    } 
} else {
    header('Location: php1.php?m=nodata');
    exit();
}
ob_end_flush();
?>

php3

<?php 
session_start();
$M = '';
if (isset($_GET['m'])) {
    $M = $_GET['m'];
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<?php echo $M; ?>
</div>
</body>
</html>

Here is a screenshot of chrome developer:

Screenshot of Chrome Developer .Tools

  • 写回答

1条回答 默认 最新

  • drpph80800 2018-07-17 15:58
    关注

    You should change the code for php1.php like this

    <?php 
    session_start();
    $M = '';
    if (isset($_GET['m'])) {
        $M = $_GET['m'];
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $('#send').click(function () {
          var str = '1234';
          $.post('php2.php',
            {
            email: str
            },
            function (data, status) {
              $("#content").html(data); // <----- ADDED
            }
          );
        });
    });
    </script>
    </head>
    <body>
    <div id="content">
    <button id="send">SEND</button>
    <br>
    <?php echo $M; ?>
    </div>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度