我想安裝pjax,但它不起作用。每當我點擊一個pjax鏈接的URL得到domain.com/foo
(沒有html內容是變化)的變化,然後它更改爲domain.com/#
,然後正常重定向到domain.com/foo
。爲什麼?pjax不工作與laravel
我這是怎麼引發pjax: $(document).pjax('a[data-pjax]', '#wrapper');
在我的控制器我有這樣的:
public function getIndex() {
$posts = $this->loginOptions();
$this->layout->title = 'My title';
$content = View::make('foo.bar')
->with('title', $this->layout->title)
->with('posts', []);
if (Request::header('X-PJAX'))
return $content;
else
$this->layout->content = $content;
}
我的HTML(第一,我點擊鏈接頁面)看起來是這樣的:
<DOCTYPE html>
<head></head>
<html>
<body>
<div id='wrapper'>
<a data-pjax href='foo'>Foobar</a>
</div>
<script src='http://code.jquery.com/jquery-2.0.0.min.js'></script>
<script src='jquery.pjax.js'></script>
<script src='script.js'></script>
</body>
</html>
如果我用X-PJAX頭部運行標準ajax調用,我得到正確的html(這意味着我的If正在工作),但url不會改變,這就是爲什麼我想要使用pjax。
$.ajax({
url: '/login',
type: 'get',
beforeSend: function(xhr){
xhr.setRequestHeader('X-PJAX', true);
xhr.setRequestHeader('X-PJAX-Container', '#wrapper')
},
success: function(resp) { $('#wrapper').html(resp); }
})
你看過https://github.com/vtalbot/pjax了嗎? –
我測試過了,並且https://github.com/simonstamm/laravel-pjax和兩者都有相同的問題。 – Marwelln