duanke6057 2013-03-24 11:00
浏览 79

PJAX和Firefox后退按钮问题

I'm testing jquery.pjax.js and noticed a problem.
In my minimum test project, strange behavior like below happens:

  1. Access to index.php in fireflx
  2. Click a pjax link: location bar and page contents are changed
  3. Click Firefox's back button: location bar is changed but contents remain

This behavior doesn't happen in GoogleChrome.
I want to know how to solve this.

My test project is:
http://karasunouta.com/php_test/pjax/
http://karasunouta.com/files/pjax.zip

index.php

<?php
    $page = 1;
    if (isset($_GET['page'])) {
        $page = $_GET['page'];
    }

    $isPjax = false;
    if (!empty($_SERVER['HTTP_X_PJAX'])) {
        $isPjax = true;
    }

    if (!$isPjax):
?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>page<?php echo $page; ?></title>
            <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
            <script type="text/javascript" src="js/jquery.pjax.js"></script>
            <script type="text/javascript">
                $(function(){
                    // link
                    $(document).pjax('a.pjax', '#main');

                    // form
                    $(document).on('submit', 'form', function(event) {
                        $.pjax.submit(event, '#main')
                    })
                });
            </script>
        </head>
        <body>
            <h1>pjax test</h1>
            <ul class="links">
                <li><a href="?page=1" class="pjax">page1</a></li>
                <li><a href="?page=2" class="pjax">page2</a></li>
                <li><a href="?page=3" class="pjax">page3</a></li>
            </ul>
            <form>
                Page:<input name="page" type="text" value="1">
                <input type="submit">
            </form>
            <div id="main" style="border: 3px double gray">
<?php endif; ?>
                <?php include("page/{$page}.html") ?>
<?php if (!$isPjax): ?>
            </div>
        </body>
    </html>
<?php endif; ?>

page/1.html

page1 contents

page/2.html

page2 contents

page/3.html

page3 contents

js/jquery-1.9.1.min.js
js/jquery.pjax.js

  • 写回答

1条回答 默认 最新

  • dqz86173 2013-03-27 10:50
    关注

    I could have found a solution by myself...

    before:

    $(function(){
        // apply pjax
    });
    

    after:

    $(document).ready(function() {
        // apply pjax
    });
    

    Now firefox back button looks working fine.
    I'm not sure about reason why.
    Actual behaviors of them looks different though several texts says the two writing form meanings are exactly same...

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch