【问题标题】:chrome + back to post + reload = ajax errorchrome + back to post + reload = ajax错误
【发布时间】:2013-09-28 11:34:18
【问题描述】:

问题:谷歌浏览器出现 ajax 错误

index.html --- POST ---> page1.php --- 链接 ---> page2.html

  1. “index.html”包含一个<form>,它发布到“page1.php”
  2. “page1.php”包含指向“page2.html”的链接
  3. “page1.php”包含对“ajax.php”的 ajax 调用

如何让问题出现?

  1. 访问“index.html”
  2. 发布到“page1.php”
  3. 点击“page2.html”链接
  4. 使用返回按钮返回“page1.php”
  5. 用 F5 重新加载“page1.php”
  6. 接受重新提交数据
  7. ajax 错误:ajax 调用失败,错误消息为空

为什么……那个东西?

index.html:

<html>
  <head>
  </head>
  <body>
    index
    <form method="post" action="page1.php">
      <input type="submit">
    </form>
  </body>
</html>

page1.php:

<html>
  <head>
    <script src="jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      function call_ajax()
      {
        $.ajax
        (
          {
            type: "POST",
            url: "ajax.php",
            success: function( response )
            {
              console.log( response );
            },
            error: function (xhr, ajaxOptions, thrownError)
            {
              console.log( '%o', xhr );
              console.log( '%o', xhr.responseText );
              console.log( '%o', thrownError );
            }
          }
        );
      }

      $( document ).ready(function() {
        call_ajax();
      });
    </script>
  </head>
  <body>
    page 1
    <a href="page2.html">page2</a>
  </body>
</html>

page2.html:

<html>
  <head>
  </head>
  <body>
    page 2
    <a href="javascript:history.back()">back</a>
  </body>
</html>

ajax.php:

<?php
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  ini_set('error_reporting', E_ALL);
  header('Cache-Control: no-cache, must-revalidate');
  header('Content-type: application/json');
  $r = array( 'message' => 'one two one two, this is a test' );
  echo json_encode( $r );
?>

【问题讨论】:

    标签: ajax google-chrome post reload back


    【解决方案1】:

    可能是您的服务器/浏览器配置有问题?

    我尝试通过使用 PHP 通过 fastcgi 并运行 Chromium 版本 30.0.1553.0 (209444) 在本地安装 lighttpd 中创建具有与上述完全相同的代码的文件来确认您的问题,但无法重现您的问题。

    查看控制台时,无论我是从 index.html 还是从 page2.html 使用“返回”链接访问 page1.php 并使用 F5 刷新,日志始终显示正确的输出。

    Object {message: "one two one two, this is a test"}
    

    【讨论】:

    • 确实,我尝试过使用另一个版本的 google chrome,但无法重现该问题。问题出现在这个版本:25.0.1364.152 谢谢你的回答,谜团解决了。
    猜你喜欢
    • 2019-05-31
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    相关资源
    最近更新 更多