背景:我正在構建一個網站,當點擊各種<a>
元素並且該功能正在工作時,它使用pjax從html片段加載容器的內容。PHP使PJAX與刷新按鈕一起工作?
問題:當我嘗試刷新通過pjax加載內容的頁面時,刷新的頁面只包含HTML片段。我理解PHP可能會在這裏發揮作用,我已經試過包含此代碼fragment.php
文件替換我fragment.html
文件之一:
<?php $headers = getallheaders();
if($headers['X-PJAX'] == 'true'):
?><p>
This text appears when page is reached by clicking a pjax link
</p>
<?php
else: ?>
<h2>This text should appear when page is refreshed, and could include the full HTML so the page will render complete if it's refreshed</h2>
<?php endif ?>
然而,這種方法是行不通的(我得到了一個服務器端錯誤)。 PHP應該在哪裏尋求解決這個問題?