'How to load JavaScript (jQuery) on pjax:ready and document.ready
I am using pjax for most of my pages. For some of them I need to include jQuery scripts.
When I load a page with pjax all scripts in $(document).on('ready pjax:success', function() { ... } are working fine, although if the page is loaded directly scripts in above function will not work, and other way round - scripts inside $(document).ready(function() {...} wont work if page is loaded with pjax.
Is there a way to detect if the page was loaded with pjax and use document.ready if it wasn't?
Thanks for all help in advance.
Solution 1:[1]
See https://api.jquery.com/ready/
There is also $(document).on( "ready", handler ), deprecated as of jQuery 1.8 and removed in jQuery 3.0.
My quick fix was this:
function myFunction() { ... }
$(myFunction)
$(document).on('pjax:end', myFunction)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | brad |
