Ajaxified widget not loading when jQuery is in the footer
-
In case of all scripts including jQuery are loaded in the footer and you’re trying to use a widget with ajax update, it will break because the inline script was loaded before jQuery. So this was discussed before in the thread.
To resolve it for myself, I’ve replaced the original jQuery code within
widget function
with the pure javascript. That solves the problem without a need to keep jQuery always loading into the header.<script type="text/javascript"> var request = ( window.XMLHttpRequest ) ? new XMLHttpRequest() : new ActiveXObject( "Microsoft.XMLHTTP" ); request.open('GET', '<?php echo admin_url('admin-ajax.php?action=wpp_get_popular&id='. $this->number . ''); ?>', true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); request.onload = function() { if (request.status >= 200 && request.status < 400) { var el = document.getElementById('<?php echo $widget_id; ?>'); el.insertAdjacentHTML('afterbegin', request.responseText); } else { if ( window.console && window.console.log ) { window.console.log('WordPress Popular Posts: jQuery is not defined!'); } } }; request.send(); </script>
Hector, probably it would be a good idea to include it to the plugin?
https://www.ads-software.com/plugins/wordpress-popular-posts/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Ajaxified widget not loading when jQuery is in the footer’ is closed to new replies.