everybody! I try to use jquery-pjax I have html code with fragments:
<li id="left_menu_item"><a href="myurl">Caption</a></li>
...
<div class="right-block" id="content">
</div>
and js-code
$(document).pjax('a', '#content');
$(document).on('pjax:send', function() {
console.log('pjax:send');
});
$(document).on('pjax:plete', function() {
console.log('pjax:plete');
});
$(document).on('pjax:success', function() {
console.log('pjax:success');
});
$(document).on('pjax:error', function() {
console.log('pjax:error');
});
$(document).on('pjax:timeout', function() {
console.log('pjax:timeout');
});
And I receive 'pjax:error' and 'pjax:timeout' messages. Ok. I added
$.pjax.defaults.timeout = false;
Now in Javascript console all right: 'pjax:send' and 'pjax:plete'. But page reload after this! Why?
everybody! I try to use jquery-pjax I have html code with fragments:
<li id="left_menu_item"><a href="myurl">Caption</a></li>
...
<div class="right-block" id="content">
</div>
and js-code
$(document).pjax('a', '#content');
$(document).on('pjax:send', function() {
console.log('pjax:send');
});
$(document).on('pjax:plete', function() {
console.log('pjax:plete');
});
$(document).on('pjax:success', function() {
console.log('pjax:success');
});
$(document).on('pjax:error', function() {
console.log('pjax:error');
});
$(document).on('pjax:timeout', function() {
console.log('pjax:timeout');
});
And I receive 'pjax:error' and 'pjax:timeout' messages. Ok. I added
$.pjax.defaults.timeout = false;
Now in Javascript console all right: 'pjax:send' and 'pjax:plete'. But page reload after this! Why?
Share Improve this question asked Feb 12, 2013 at 5:09 indapublicindapublic 2,32810 gold badges39 silver badges50 bronze badges 7- Browsers Chrome 24.0 & Firefox 17.0 – indapublic Commented Feb 12, 2013 at 5:09
- In the browser's developer tools, you should be able to configure the console to persist even after the reload. Have you done that? And when you do, can you tell if the error callback is being fired? – Ian Clelland Commented Feb 12, 2013 at 5:22
-
Yes, i did it earlier. There is no messages about error.
pjax:send myscript.js:10 pjax:plete myscript.js:13 pjax:send myscript.js:10 pjax:plete myscript.js:13
That's all. – indapublic Commented Feb 12, 2013 at 6:32 -
Do you need to use the
fragment
option? – Sean Hogan Commented Feb 12, 2013 at 9:59 - @SeanHogan I don't use it now. – indapublic Commented Feb 13, 2013 at 8:59
2 Answers
Reset to default 14When jquery-pjax
is used to progressively enhance a static HTML site you must use the fragment
option.
In your case the code would be something like:
$(document).pjax('a', '#content', { fragment: '#content' });
You should also ensure that your HTML is valid - jquery-pjax
parsing of HTML isn't exactly like the browser
jquery-pjax
also has a bug where text-nodes that are direct children of the fragment are stripped. Make sure your content is wrapped in elements, e.g.
<div id="content">
<p>Page 1</p>
</div>
$(document).pjax('a', '#content', { push: false, replaceRedirect: false });