Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery pjax不工作_Jquery_History.js_Pjax - Fatal编程技术网

Jquery pjax不工作

Jquery pjax不工作,jquery,history.js,pjax,Jquery,History.js,Pjax,我的pjax有问题 我在下载了最新的pjax 然后我编写了演示代码,但它不起作用。 main.html <!DOCTYPE html> <html> <head> <title>main.html</title> <script type="text/javascript" src="../js/jquery/jquery-1.8.2.min.js"></script> <scrip

我的pjax有问题

我在下载了最新的pjax

然后我编写了演示代码,但它不起作用。 main.html

<!DOCTYPE html>
<html>
<head>
    <title>main.html</title>
    <script type="text/javascript" src="../js/jquery/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery/plugin/jquery.pjax.js"></script>
    <script>
        $(function(){
            $(window.document).pjax('a', '#pjax-container')
        });
    </script>
</head>
<body>
    <h1>My Site</h1>
    <div class="container" id="pjax-container">
        Go to <a href="MyHtml.html">next page</a>.
    </div>
</body>
</html>
以及MyHtml.html,如下所示

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>MyHtml.html</title>
  </head>
  <body>
    This is my HTML page. <br>
  </body>
</html>
当我点击链接时,它会直接转发到MyHtml.html。我的代码有问题吗


我可以肯定pjax已经起作用了,当我单击返回main.html的按钮时,它会返回到我在main.html之前使用的另一个页面。

因为您使用的是静态html页面,所以需要片段选项。您的pjax配置可能是:

$(function() {
    $(document).pjax('a', '#pjax-container', { 
        fragment: '#pjax-container', 
        timeout: 3000 
    });
});
此外,所有页面都需要类似的标记,只有pjax容器的内容不同。pjax容器的内容应该是页面之间唯一可以更改的内容。 您的MyHtml.html页面可能应该是:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>MyHtml.html</title>
    <script type="text/javascript" src="../js/jquery/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery/plugin/jquery.pjax.js"></script>
    <script>
    $(function() {
      $(document).pjax('a', '#pjax-container', { 
        fragment: '#pjax-container', 
        timeout: 3000 
      });
    });
    </script>
  </head>
  <body>
    <h1>My Site</h1>
    <div id="pjax-container">
      This is my HTML page. <br />
      Go to the <a href="main.html">main page</a>
    </div>
  </body>
</html>

您没有遵循jquery pjax说明。您可以编辑问题以包含MyHtml.html的内容吗?MyHtml.html只是一个hello world页面。没有脚本或元。正文中只有“hello world”。我也遵循jquery pjax说明。但它不起作用,如果没有演示URL,没有页面的最新代码,我所能做的就是猜测。你是想一直猜测,直到某个东西起作用,还是想真正理解?我像你一样做了,但没有起作用。它刷新了整个页面。我可以给你发电子邮件吗?对不起,我没有演示url。我复制了pjax支持的演示。但它也不起作用。chrome的控制台中没有错误。您在哪里看到以下要求?所有页面都需要类似的标记,只有pjax容器的内容不同