问题是,一旦pjaxed请求完成,pjax也会启动正常的GET请求。
我的代码是这样的:
$(document).on('pjax:end', function(event){
alert("end");
inpjax = false;
});
$(document).on('pjax:timeout', function(event) {
alert("timeout")
event.preventDefault();
});
$(document).on('pjax:error', function() {
alert("error");
});
$(document).on('pjax:success', function() {
alert("success");
});
$(document).ready(function(e) {
inpjax = false;
$('.pj').click( function(e) {
e.preventDefault();
if(!inpjax)
{
inpjax = true;
$.pjax({
timeout: 5000,
url: $(this).attr('href'),
container: '#codeport'
});
}
});
});
正如你所看到的,它应该给我一个关于不同侮辱的警报,但是我只对pjax:end事件发出警报,并且在那个警报之后,pjax启动正常的GET请求,时间是这样的:
[17:36:02.002] GET http://localhost/abstract?_pjax=%23codeport [HTTP/1.1 200 OK 86 ms]
[17:36:02.170] GET http://localhost/abstract [HTTP/1.1 200 OK 73 ms]
我没有超时,错误或成功警报。
可能导致这种情况的原因是什么?请帮忙......
SOLUTION:
问题原来是我的服务器端代码正在响应整页,这导致了第二个GET请求。因此,如果您遇到此问题,请确保您的服务器端代码正确响应PJAX请求。
答案 0 :(得分:0)
示例:
<!DOCTYPE html>
<html>
<head>
<!-- styles, scripts, etc -->
</head>
<body>
<h1>My Site</h1>
<div class="container" id="pjax-container">
Download content from <a href="/page/2"> the other site </a>?.
</div>
</body>
</html>
尝试将pjax添加到要从$(document).pjax('a', '#pjax-container')