admin管理员组文章数量:1022695
I'm trying to write a site with content loaded into a div at runtime using PJAX. The PHP files that i request with the PJAX all include a header and footer, which only produce content if isset($_SERVER['X-PJAX'])
However, when i use the PJAX to load the PHP file, the entire page refreshes. I would assume it's something wrong with my PJAX code, but loading a plain HTML file works fine.
EDIT: In case it is of help, i'm currently running all this on WAMP Server 2.2 running on localhost. It's what i do all my dev stuff in.
for reference, here's the JS i'm using to load the content, and an example of a php page
JS:
if ( $.support.pjax ) {
//disable <a> tabs, store value of href so pjax can use it
$('header a').each(function () {
$(this)
.attr('pjax', $(this).attr('href'))
.removeAttr('href')
.css('cursor','pointer')
})
//link up the pjax
.live('click', function () {
var link = $(this)
$('#content').animate({opacity:0}, {duration:500, plete:function(){
$.pjax({
url: link.attr('pjax'),
container: '#content',
plete: function() {
$('#content').animate({opacity:1}, 500);
}
});
}});
});
}
PHP:
//header.php
<?php
//If we are loading with pjax, ignore the header
if (!isset($_SERVER['X-PJAX'])) {
?>
<!-- head section, opening body tags, etc -->
<div role="main" id="content">
<?php } ?>
//foo.php
<?php include 'header.php'; ?>
<p>sample content</p>
<?php include 'footer.php'; ?>
//footer.php
<?php
if (!isset($_SERVER['X-PJAX'])) {
?>
</div>
<!-- load scripts, etc-->
<?php } ?>
I'm trying to write a site with content loaded into a div at runtime using PJAX. The PHP files that i request with the PJAX all include a header and footer, which only produce content if isset($_SERVER['X-PJAX'])
However, when i use the PJAX to load the PHP file, the entire page refreshes. I would assume it's something wrong with my PJAX code, but loading a plain HTML file works fine.
EDIT: In case it is of help, i'm currently running all this on WAMP Server 2.2 running on localhost. It's what i do all my dev stuff in.
for reference, here's the JS i'm using to load the content, and an example of a php page
JS:
if ( $.support.pjax ) {
//disable <a> tabs, store value of href so pjax can use it
$('header a').each(function () {
$(this)
.attr('pjax', $(this).attr('href'))
.removeAttr('href')
.css('cursor','pointer')
})
//link up the pjax
.live('click', function () {
var link = $(this)
$('#content').animate({opacity:0}, {duration:500, plete:function(){
$.pjax({
url: link.attr('pjax'),
container: '#content',
plete: function() {
$('#content').animate({opacity:1}, 500);
}
});
}});
});
}
PHP:
//header.php
<?php
//If we are loading with pjax, ignore the header
if (!isset($_SERVER['X-PJAX'])) {
?>
<!-- head section, opening body tags, etc -->
<div role="main" id="content">
<?php } ?>
//foo.php
<?php include 'header.php'; ?>
<p>sample content</p>
<?php include 'footer.php'; ?>
//footer.php
<?php
if (!isset($_SERVER['X-PJAX'])) {
?>
</div>
<!-- load scripts, etc-->
<?php } ?>
Share
Improve this question
edited Feb 27, 2012 at 4:00
AClockWorkLemon
asked Feb 27, 2012 at 3:21
AClockWorkLemonAClockWorkLemon
112 silver badges3 bronze badges
7
- Did you check browser's error console for messages? – Cheery Commented Feb 27, 2012 at 3:38
- Yeah, nothing es up at all. – AClockWorkLemon Commented Feb 27, 2012 at 3:40
- I'm getting the feeling that it is something to do with PHP. Almost like the PHP daemon is noticing a request to a PHP file and just spamming the whole file out. But i could be very wrong. – AClockWorkLemon Commented Feb 27, 2012 at 3:59
- Look at the requests made to the server and its answers (almost every browser can show it). PHP should not create this kind of behavior. The best way is to give a link to a page with a problem. – Cheery Commented Feb 27, 2012 at 4:05
- Ok. I officially feel stupid. It would seem to be an issue with my local server setup or something. On uploading it to my webhost to display the issue it works fine. I suppose now the question is working out how to make said local server work properly -_- – AClockWorkLemon Commented Feb 27, 2012 at 5:35
1 Answer
Reset to default 6i always have more luck with just using
$_SERVER["HTTP_X_PJAX"]
Here is the github repo i made of a fully functional PJAX php example, for those that need all the source code to look at to get up and running, and may help anyone else out there searching for PJAX php inplementation
https://github./Jrizzi1/pjaxphp
I'm trying to write a site with content loaded into a div at runtime using PJAX. The PHP files that i request with the PJAX all include a header and footer, which only produce content if isset($_SERVER['X-PJAX'])
However, when i use the PJAX to load the PHP file, the entire page refreshes. I would assume it's something wrong with my PJAX code, but loading a plain HTML file works fine.
EDIT: In case it is of help, i'm currently running all this on WAMP Server 2.2 running on localhost. It's what i do all my dev stuff in.
for reference, here's the JS i'm using to load the content, and an example of a php page
JS:
if ( $.support.pjax ) {
//disable <a> tabs, store value of href so pjax can use it
$('header a').each(function () {
$(this)
.attr('pjax', $(this).attr('href'))
.removeAttr('href')
.css('cursor','pointer')
})
//link up the pjax
.live('click', function () {
var link = $(this)
$('#content').animate({opacity:0}, {duration:500, plete:function(){
$.pjax({
url: link.attr('pjax'),
container: '#content',
plete: function() {
$('#content').animate({opacity:1}, 500);
}
});
}});
});
}
PHP:
//header.php
<?php
//If we are loading with pjax, ignore the header
if (!isset($_SERVER['X-PJAX'])) {
?>
<!-- head section, opening body tags, etc -->
<div role="main" id="content">
<?php } ?>
//foo.php
<?php include 'header.php'; ?>
<p>sample content</p>
<?php include 'footer.php'; ?>
//footer.php
<?php
if (!isset($_SERVER['X-PJAX'])) {
?>
</div>
<!-- load scripts, etc-->
<?php } ?>
I'm trying to write a site with content loaded into a div at runtime using PJAX. The PHP files that i request with the PJAX all include a header and footer, which only produce content if isset($_SERVER['X-PJAX'])
However, when i use the PJAX to load the PHP file, the entire page refreshes. I would assume it's something wrong with my PJAX code, but loading a plain HTML file works fine.
EDIT: In case it is of help, i'm currently running all this on WAMP Server 2.2 running on localhost. It's what i do all my dev stuff in.
for reference, here's the JS i'm using to load the content, and an example of a php page
JS:
if ( $.support.pjax ) {
//disable <a> tabs, store value of href so pjax can use it
$('header a').each(function () {
$(this)
.attr('pjax', $(this).attr('href'))
.removeAttr('href')
.css('cursor','pointer')
})
//link up the pjax
.live('click', function () {
var link = $(this)
$('#content').animate({opacity:0}, {duration:500, plete:function(){
$.pjax({
url: link.attr('pjax'),
container: '#content',
plete: function() {
$('#content').animate({opacity:1}, 500);
}
});
}});
});
}
PHP:
//header.php
<?php
//If we are loading with pjax, ignore the header
if (!isset($_SERVER['X-PJAX'])) {
?>
<!-- head section, opening body tags, etc -->
<div role="main" id="content">
<?php } ?>
//foo.php
<?php include 'header.php'; ?>
<p>sample content</p>
<?php include 'footer.php'; ?>
//footer.php
<?php
if (!isset($_SERVER['X-PJAX'])) {
?>
</div>
<!-- load scripts, etc-->
<?php } ?>
Share
Improve this question
edited Feb 27, 2012 at 4:00
AClockWorkLemon
asked Feb 27, 2012 at 3:21
AClockWorkLemonAClockWorkLemon
112 silver badges3 bronze badges
7
- Did you check browser's error console for messages? – Cheery Commented Feb 27, 2012 at 3:38
- Yeah, nothing es up at all. – AClockWorkLemon Commented Feb 27, 2012 at 3:40
- I'm getting the feeling that it is something to do with PHP. Almost like the PHP daemon is noticing a request to a PHP file and just spamming the whole file out. But i could be very wrong. – AClockWorkLemon Commented Feb 27, 2012 at 3:59
- Look at the requests made to the server and its answers (almost every browser can show it). PHP should not create this kind of behavior. The best way is to give a link to a page with a problem. – Cheery Commented Feb 27, 2012 at 4:05
- Ok. I officially feel stupid. It would seem to be an issue with my local server setup or something. On uploading it to my webhost to display the issue it works fine. I suppose now the question is working out how to make said local server work properly -_- – AClockWorkLemon Commented Feb 27, 2012 at 5:35
1 Answer
Reset to default 6i always have more luck with just using
$_SERVER["HTTP_X_PJAX"]
Here is the github repo i made of a fully functional PJAX php example, for those that need all the source code to look at to get up and running, and may help anyone else out there searching for PJAX php inplementation
https://github./Jrizzi1/pjaxphp
本文标签: javascriptPJAX not working when requesting PHP fileStack Overflow
版权声明:本文标题:javascript - PJAX not working when requesting PHP file - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745546166a2155403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论