chrome +返回发布+重新加载= ajax错误

时间:2013-09-23 14:12:35

标签: ajax google-chrome post reload back

问题:google chrome的ajax错误

index.html --- POST ---> page1.php --- link ---> page2.html

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

    如何解决问题?

    1. 访问“index.html”
    2. 发布到“page1.php”
    3. 点击链接到“page2.html”
    4. 使用后退按钮
    5. 返回“page1.php”
    6. 使用F5
    7. 重新加载“page1.php”
    8. 接受重新提交数据
    9. ajax错误:ajax调用失败并显示空错误消息
    10. 为什么......那件事?

      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 );
      ?>
      

1 个答案:

答案 0 :(得分:0)

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

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

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

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