我将网站部分划分为不同的文件时遇到问题,因此编辑起来比较容易,但是我遇到了一些问题..网站无效..
这是原作的部分:
<?php if($_SERVER["HTTP_X_PJAX"]): ?>
<div id="main">first change</div>
<?php else: ?>
<html>
<head>
<script src="http://pjax.heroku.com/jquery.js"></script>
<script src="http://pjax.heroku.com/jquery.cookie.js"></script>
<script src="http://pjax.heroku.com/jquery.pjax.js"></script>
<script type="text/javascript">
$(function() { $('a').pjax('#main');
$('#main').bind('pjax:start', function(){$('#main').animate({ height: 'hide', opacity: 'hide' }, 'fast')})
.bind('pjax:end', function(){$('#main').animate({ height: 'show', opacity: 'show' }, 'slow')}); });
</script>
</head>
<body>
<?php
$header = "this is first part
<br/> <a href='test2.php' data-pjax='main'>GO</a>";
$date = date("Y-m-d H:i:s");
$footer = "this is first part";
echo "$header<br/>$date<br /><div id='main'>first page</div><br />$footer";
?>
</body>
</html>
<?php endif; ?>
这就是我现在所拥有的,但它不起作用:
<?php $body = "<div id='main'>first page</div><br /><a href='pjax2.php' data-pjax='main'>GO BACK</a>"; ?>
<?php if($_SERVER["HTTP_X_PJAX"]): ?>
<?php echo "$body";?>
<?php else: ?><?php include "header.php";?>
<?php echo "$body"; ?><?php include "footer.php" ;>
<?php endif; ?>
Header.php是这样的:
<html>
<head>
<script src="http://pjax.heroku.com/jquery.js"></script>
<script src="http://pjax.heroku.com/jquery.cookie.js"></script>
<script src="http://pjax.heroku.com/jquery.pjax.js"></script>
<script type="text/javascript">
$(function() { $('a').pjax('#main');
$('#main').bind('pjax:start', function(){$('#main').animate({ height: 'hide', opacity: 'hide' }, 'fast')})
.bind('pjax:end', function(){$('#main').animate({ height: 'show', opacity: 'show' }, 'slow')}); });
</script>
</head>
<body>
Footer.php是这样的:
</body></html>
答案 0 :(得分:1)
尝试通过以下方式替换您的代码:
- 删除未使用的php标签
- 确保header.php
和footer.php
与当前文件位于同一目录中。
<?php
$body = "<div id='main'>first page</div><br /><a href='pjax2.php' data-pjax='main'>GO BACK</a>";
if($_SERVER["HTTP_X_PJAX"]) {
echo $body;
} else {
include("header.php");
echo $body;
include("footer.php");
}
?>