You have the correct selector, there is no need to change it, you can use the $.pjax directly:
$('input[name="group2"]').on('change', function(){ $.pjax({ url: '/url', container: '#container', beforeSend: function(){ $('#message').text( 'Loading...' ); }, complete: function(){ $('#message').text( 'Loaded' ); } }); });
Or you can also disable callbacks and use send & complete , and also better if you are in boot mode, as described in the Official Documentation :
pjax: send and pjax: complete are a good couple of events to use if you implement a load indicator
$(function(){ $('input[name="group2"]').on('change', function(){ $.pjax({url: "/url", container: '#container'}) }); $(document).on('pjax:send', function() { $('#message').text( 'Loading...' ); }) $(document).on('pjax:complete', function() { $('#message').text( 'Loaded' ); }) })
NOTE. There is no need for a ready callback, as it will start your #message with Loaded when the page $.pjax before any $.pjax request.
Take a look at the best way to implement overlay with pjax .
Hope this helps.
source share