问题是,一旦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]我没有超时,错误或成功警报。
是什么导致了这一切?请帮帮我..。
解决方案:
问题是,我的服务器端代码是用一个完整的页面进行响应的,这导致了第二个GET请求。因此,如果您也遇到此问题,请确保服务器端代码对PJAX请求作出正确的响应。
发布于 2013-07-05 15:05:28
示例:
<!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')中获取事件消息的元素中。
https://stackoverflow.com/questions/17491824
复制相似问题