2013-03-26 127 views
0

幫助,我與pjax麻煩。pjax does not工作

我下載最新的pjax在https://github.com/defunkt/jquery-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 directly.is有我的代碼什麼問題?

我可以確定pjax已經工作了一些東西,當我點擊後退按鈕到main.html,它回到我在main.html之前使用的另一個頁面。

+0

你沒有關注的jQuery的pjax指令。 – 2013-04-02 22:46:26

+0

您可以編輯問題以包含「MyHtml.html」的內容嗎? – 2013-04-05 04:16:42

+0

MyHtml.html只是一個你好世界page.no腳本或元.only在體內的'你好世界'。 – miles 2013-04-05 12:01:01

回答

10

由於您使用靜態HTML頁面,您將需要fragment選項。你pjax配置大概應該是:

$(function() { 
    $(document).pjax('a', '#pjax-container', { 
     fragment: '#pjax-container', 
     timeout: 3000 
    }); 
}); 

此外,所有網頁都需要有類似的標記,與#pjax-container是不同的唯一內容。 #pjax-container的內容應該是頁面之間唯一更改的內容。 你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> 
+0

我做了像你一樣,但沒有工作。它新鮮的整個page.may我給你發電子郵件? – miles 2013-04-04 16:31:10

+0

你有一個演示網址嗎? – 2013-04-04 22:07:06

+0

對不起,我沒有演示url.i複製了pjax支持的演示。但它也沒有工作。並且在Chrome的控制檯中沒有錯誤。 – miles 2013-04-05 00:31:59