Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php PJAX不工作_Php_Jquery_Ruby On Rails_Ajax_Pjax - Fatal编程技术网

Php PJAX不工作

Php PJAX不工作,php,jquery,ruby-on-rails,ajax,pjax,Php,Jquery,Ruby On Rails,Ajax,Pjax,我的pjax无法工作,因为我看到时间在变化 你能发现我的代码有问题吗 <html><head> <script src="jquery.js"></script> <script src="jquery.cookie.js"></script> <script src="jquery.pjax.js"></script> <script type="text/javascript"> $(

我的pjax无法工作,因为我看到时间在变化

你能发现我的代码有问题吗

<html><head>
<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery.pjax.js"></script>
<script type="text/javascript">
$('a[data-pjax]').pjax()
</script>
</head><body>
<?php
$header = "this is first part
<br/> <a href='pjax2.php' data-pjax='main'>GO</a>";
$date = date("Y-m-d H:i:s");
$footer = "this is second part";
$headers = getallheaders();
if(($headers['X-PJAX'] == 'true')){
echo "<div id='main'>first change</div>";
}else{
echo "$header<br/>$date<br /><div id='main'>first page</div><br />$footer";
}
?>
</body></html>

$('a[data pjax]')。pjax()

编辑:主要问题是,您试图使用尖端浏览器功能,但尚未掌握网页的基本调试。

您使用php中的
getallheaders()
解决了该错误,因此这对您来说应该很容易

步骤1:加载、打开浏览器控制台、刷新页面并检查控制台中的消息

它报告未定义
$的错误。这表明
jquery
没有成功加载

步骤2:加载

一个谜团解开了

在解决了页面上所有明显的问题之后,再看看更模糊的东西。对于pjax,这将涉及网络资源、http请求和响应头等的检查

如果您正在使用Firefox的Firebug,请阅读了解详细信息。 对于pjax,如果pjax失败,您需要打开
persist
选项

以下内容可能会解决测试页面的其他问题…

当响应
X-PJAX
请求时,您只发送主要内容,而不是整个页面。对于您的测试用例

<?php $headers = getallheaders();
      if($headers['X-PJAX'] == 'true'): ?>
first change
<?php else: ?>
<html>
<head>
<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery.pjax.js"></script>
<script type="text/javascript">
$(function() { $('a[data-pjax]').pjax(); });
</script>
</head>
<body>
<?php
  $header = "this is first part
    <br/> <a href='pjax2.php' data-pjax='main'>GO</a>";
  $date = date("Y-m-d H:i:s");
  $footer = "this is second part";
  echo "$header<br/>$date<br /><div id='main'>first page</div><br />$footer";
?>
</body>
</html>
<?php endif; ?>

第一次改变
$(function(){$('a[data pjax]').pjax();});

编辑:主要问题是,您试图使用尖端浏览器功能,但尚未掌握网页的基本调试。

您使用php中的
getallheaders()
解决了该错误,因此这对您来说应该很容易

步骤1:加载、打开浏览器控制台、刷新页面并检查控制台中的消息

它报告一个未定义
$的错误
。这表明
jquery
没有成功加载

步骤2:加载

一个谜团解开了

在解决了页面上所有明显的问题之后,再看看更模糊的东西。对于pjax,它将涉及到网络资源、http请求和响应头的检查等

如果您正在使用Firefox的Firebug,请阅读了解详细信息。 对于pjax,如果pjax失败,您需要打开
persist
选项

以下内容可能会解决测试页面的其他问题…

当响应
X-PJAX
请求时,您只发送主要内容,而不是整个页面。对于您的测试用例

<?php $headers = getallheaders();
      if($headers['X-PJAX'] == 'true'): ?>
first change
<?php else: ?>
<html>
<head>
<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery.pjax.js"></script>
<script type="text/javascript">
$(function() { $('a[data-pjax]').pjax(); });
</script>
</head>
<body>
<?php
  $header = "this is first part
    <br/> <a href='pjax2.php' data-pjax='main'>GO</a>";
  $date = date("Y-m-d H:i:s");
  $footer = "this is second part";
  echo "$header<br/>$date<br /><div id='main'>first page</div><br />$footer";
?>
</body>
</html>
<?php endif; ?>

第一次改变
$(function(){$('a[data pjax]').pjax();});

我认为您需要将
.pjax()
函数放入
$(document).ready(function(){})中。这与RubyonRails到底有什么关系?我认为您需要将
.pjax()
函数放在
$(document.ready(function(){})中。这与RubyonRails到底有什么关系?它仍然不起作用
$(document).ready(function(){$('a').pjax('main').live('click',function(){$(this.showLoader()});})更改一个

$(document.ready(function(){$('a').pjax('main').live('click',function(){$(this.showLoader());})更改一个.showLoader()});})更改第一页的哪个部分?我更改了标题请求,因为您的选项出现了一些错误。我已编辑了答案以提供完整的源代码。这只是为了明确pjax的需求。如果没有访问实际的测试页面,就无法判断这是否有效。我更新了答案。请注意,
pages.js
脚本(您最近加入的)禁用了pjax。它仍然不起作用
$(document).ready(函数(){$('a').pjax('main').live('click',函数(){$(this.showLoader());})更改一个


第一页
pages.js
脚本(您最近加入的)禁用了pjax。