the documented `ready pjax:end` does not work with Jquery 3.4.1 or 2.2.4
Author: buttflatteryCreated May 28, 2019Updated Apr 15, 2022
The documented code does not work as mentioned
$(document).on('ready pjax:end', function(event) {
$(event.target).initializeMyPlugin()
})The above code does not call the initializeMyPlugin() on the first page load with jquery 3.4.1 or jquery-2.2.4,
i am using the following piece of of code
function loader(){
$('.page-loader-wrapper').fadeOut();
//assign respective values to the associated hidden fields
$("#rco,#dco").on('click',function(e){
var buttonId = $(this).attr('id');
$("#"+buttonId+"_input").val(1);
});
}
$(document).on("pjax:beforeSend",function(e){
$('.page-loader-wrapper').fadeIn();
}).on("ready pjax:end",function(){
loader();
});and the loader() function is never called on the first page load, only called on pjax:end . i am using this code in Yii2 framework and the output is like below
</script><script src="/assets/9f3f0907/jquery.js"></script>
<script src="/assets/b6f73355/yii.js"></script>
<script src="/assets/b6f73355/yii.gridView.js"></script>
<script src="/assets/e0e575b7/jquery.pjax.js"></script>
<script src="/assets/27eba27c/js/bootstrap.js"></script>
<script>jQuery(function ($) {
function loader(){
$('.page-loader-wrapper').fadeOut();
//assign respective values to the associated hidden fields
$("#rco,#dco").on('click',function(e){
var buttonId = $(this).attr('id');
$("#"+buttonId+"_input").val(1);
});
}
$(document).on("pjax:beforeSend",function(e){
$('.page-loader-wrapper').fadeIn();
}).on("pjax:end",function(){
loader();
});
jQuery('#w0').yiiGridView('setSelectionColumn', {"name":"selection[]","class":null,"multiple":true,"checkAll":"selection_all"});
jQuery('#w0').yiiGridView({"filterUrl":"\/site\/test","filterSelector":"#w0-filters input, #w0-filters select","filterOnFocusOut":true});
jQuery(document).pjax("#pjax-container a", {"push":true,"replace":false,"timeout":10000,"scrollTo":false,"container":"#pjax-container"});
jQuery(document).on("submit", "#pjax-container form[data-pjax]", function (event) {jQuery.pjax.submit(event, {"push":true,"replace":false,"timeout":10000,"scrollTo":false,"container":"#pjax-container"});});
setTimeout(function () {
$('.page-loader-wrapper').fadeOut();
}, 50);
});</script></body>
</html>Source: defunkt/jquery-pjax