Skip to content

Instantly share code, notes, and snippets.

@ramsesoriginal
Created March 9, 2012 10:59
Show Gist options
  • Save ramsesoriginal/2006082 to your computer and use it in GitHub Desktop.
Save ramsesoriginal/2006082 to your computer and use it in GitHub Desktop.
PJAX-PHP: Untested Code, just as a sample how one coudl theoretically implement PJAX with PHP
<?php
$render_template=true;
if ($_SERVER["HTTP_X_PJAX"])
{
$render_template=false;
}
?>
<?php
if ($render_template) {
?>
<html>
<head>
<meta charset="utf-8" />
<title>Testing Pjax</title>
<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery.pjax.js"></script>
<script type="text/javascript">
$(function(){
$('nav a').pjax('#content')
})
</script>
</head>
<body>
Date in template: <?php echo $today = date("D M j G:i:s T Y"); ?>
<nav>
<a href="index.php?content=1" >click me for other content</a>
<a href="index.php?content=2" >click me for even more additional content</a>
</nav>
<section id="content">
<?php
}
?>
<?php
if ($_Get["content"]==1)
{
?>
<h1>Content=1</h1>
Date in content: <?php echo $today = date("D M j G:i:s T Y"); ?>
<p>
this will be replaced by pjax with the content's of <a href="index.php?content=1">index.php?content=1</a> or <a href="index.php?content=2">index.php?content=2</a>
</p>
<?php
} else {
?>
<h1>Content 2=2</h1>
Date in content: <?php echo $today = date("D M j G:i:s T Y"); ?>
<p>
this will be replaced by pjax with the content's of <a href="index.php?content=1">index.php?content=1</a> or <a href="index.php?content=2">index.php?content=2</a>
</p>
<?php
}
?>
<?php
if ($render_template) {
?>
</section>
</body>
</html>
<?php
}
?>
@chienvu
Copy link

chienvu commented Aug 17, 2013

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment