Home  >  Article  >  Backend Development  >  我再重新提问一下 那个页面跳转的问题

我再重新提问一下 那个页面跳转的问题

WBOY
WBOYOriginal
2016-06-23 13:15:56889browse

可能我没说清  我再发一遍  我做的这个想要的效果是这样的:有一个帖子列表页A页面    从A页面点击一个标题就会跳转到这个主题页面B页面  注意这里是跳转过去的  不是打开的一个新的标签  我在B页面里面发表回复再点击浏览器的返回按钮就可以返回到A页面    这个是我想要的效果 但是现在我做的这个有个bug   就是在B页面发表完回复后点击一次浏览器的返回按钮不能回到A页面  还是留在B页面  再点击一次才能回到A页面  如果在B页面提交两次回复 需要点击三次才能回到A页面   搞不懂为什么会这样啊  
 
b页面的代码如下:
tieba3.php
;
nbsp;html>







include "cookie.php";
?>


  

      $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
    $title=$_GET['id'];
    $stmt=$pdo->prepare("select id,title,content from topic where id=?");
    $stmt->execute(array($title));
    $res=$stmt->fetchall(PDO::FETCH_ASSOC);
    foreach($res as $v){
      echo ''.$v['content'].'';
    }
  ?>
     $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
   $id2=$_GET['id'];
   $stmt=$pdo->prepare("select id,reid,content from reply where reid=?");
   $stmt->execute(array($id2));
   $res1=$stmt->fetchall(PDO::FETCH_ASSOC);
    foreach($res1 as $v2){
      echo $v2['content'];
     }
   ?>
  

  

    


     ">
     " >
      
      
  

  





提交回复插入到数据库的页面 tieba4.php
if(isset($_POST['reid'])){
  $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
 $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");
 $stnt->execute($_POST);
header("location:http://localhost/tieba3.php?id=".$_POST['reid']);
}
?>


回复讨论(解决方案)

header后写个exit():试试看。

header后写个exit():试试看。


是这样吧 试了一下 不行
header("location:http://localhost/tieba3.php?id=".$_POST['reid']);
exit();

检查$_POST['reid']是否为空而出notice,在header前加ob_clean();看看

检查$_POST['reid']是否为空而出notice,在header前加ob_clean();看看


不是空的  都是正常的

A 点击连接 进入 B :历史列表 A
B 提交到 C             :历史列表 A B
C 重定向                 :历史列表 A B
所以延历史列表回到 A,需要 2 次 后退

A 点击连接 进入 B :历史列表 A
B 提交到 C             :历史列表 A B
C 重定向                 :历史列表 A B
所以延历史列表回到 A,需要 2 次 后退



那么怎么解决呢? 我是新手没有遇到过这样的问题

一个方案:
tieba4.php

<?phpif(isset($_POST['reid'])){  $pdo=new PDO("mysql:host=localhost;dbname=t1","root","");  $stnt=$pdo->prepare("insert into reply(reid,name,content)values(:reid,:name,:content)");  $stnt->execute($_POST);  echo "    <script>    history.go(-1);    location = 'tieba3.php?id={$_POST['reid']';    </script>";}?>
现在流行 ajax,页面已经不会跳转了
自然页不会依赖浏览器的 后退 按钮

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn