i just want to know how to reload multiple pjax? this is my code
$.pjax.reload({container:"#con_camp"});
$.pjax.reload({container:"#con_camp1"});
but only the #con_camp1 is the one that will reload.
i just want to know how to reload multiple pjax? this is my code
$.pjax.reload({container:"#con_camp"});
$.pjax.reload({container:"#con_camp1"});
but only the #con_camp1 is the one that will reload.
Try this.
$.pjax.reload({container: "#1-pjax", async:false});
$.pjax.reload({container: "#2-pjax", async:false});
You could just do
$.pjax.reload({container: '#container_1'}).done(function () {
$.pjax.reload({container: '#container_2'});
});
Unfortunately Pjax by design doesn't allow multiple requests. In order to do those you have to nullify xhr
parameter in $.pjax
.
Basically like this:
$.pjax.reload({container:"#con_camp"});
$.pjax.xhr = null;
$.pjax.reload({container:"#con_camp1"});
$.pjax.xhr = null; // so that some next pjax request wont cancel this reload.
When using async:false
both Chrome and Firefox are throwing this:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
A different way to do it is to use the pjax:end event that will trigger when a container is completely reloaded to register the code that will reload the next one. That way they'll get reloaded one by one:
var pjaxContainers = ['#pjax-block-1', '#pjax-block-2', '#pjax-block-3'];
$.each(pjaxContainers , function(index, container) {
if (index+1 < pjaxContainers.length) {
$(container).one('pjax:end', function (xhr, options) {
$.pjax.reload({container: pjaxContainers[index+1]}) ;
});
}
});
$.pjax.reload({container: pjaxContainers[0]}) ;
I have faced the same issue , I have done in this way.
<?php Pjax::begin(['id'=>'pjax_id']); ?>
<?php Pjax::end(); ?>
// Under SCRIPT tag
$.pjax.reload({container: '#pjax_id', async: false});
Something to add to the $.pjax.xhr=null
solution, since this by itself has a bug- it will allow an earlier, but longer-running request to load the response data into the target container after a subsequent, faster running request. This would obviously be unexpected behavior. The user expects the latest click to be the one that loads the response into the container.
The solution is to add a reference to the previous xhr object somewhere it can be accessed on the next pjax event. I use the window namespace
$('.pjax-container').on('pjax:send', function(event, xhr, options) {
// unique data attribute of the pjax container
xhrName=$(this).attr('data-myXhrName');
// abort pending requests because we are allowing multiples
if (window.xhrRef[xhrName]) {
window.xhrRef[xhrName].abort();
}
$.pjax.xhr=null;
window.xhrRef[xhrName]=xhr;
})
.on('pjax:complete', function(event, xhr, options) {
xhrName=$(this).attr('data-myXhrName');
// we're done with it
window.xhrRef[xhrName]=false;
})
© 2022 - 2024 — McMap. All rights reserved.