Using $ .getScript (jquery): code not executing

I am working on updating my website, which now uses the AJAX engine. My engine works well, for some reason some pages do not run javascript, let me explain: when changing the binding, I use $ .get to restore the data. Pages have the following structure:

title h1 script1.js,script2.js,etc.js style1.css,style2.css,etc.css <!--there the page content--> 

A page reload appears, solves the problem, but I do not understand what is different. In the previous code, the engine starts successfully, reboots or not:

 $.getScript("script1.js"); $.getScript("script2.js"); $.getScript("etc.js"); 


In addition, the created php script contains the current state of the user in the form of an object:

 $(function(){ user = new Object(); user.id = user.logged = <?php echo $user->getId();?>; user.nick = "<?php echo $user->getNick();?>"; user.mail = "<?php echo $user->getMail();?>"; user.logout = function(){ }; }); 

The $ .getScript request succeeds, but the user object does not change. However, the script has not yet been modified. And this also does not work from the console.

The update is online at v2.wawolf.com , you will find everything you need. Hot Link: Engine Code

+6
source share
2 answers

I just solved my problem: when the whole document is loaded, $ (function () {}) will no longer work , so calling a script that uses $ (function () {}) will not start. I removed it from all my secondary scripts and now everything works fine!

+3
source

it may be a download problem.

try encapsulating JS loading in onload function

 $(window).load(function(){ //get script loads here } 

or

 $(document).ready(function() { //get script loads here } 

Sometimes I use one inside the other for a dynamic JS script that should be loaded last.

+1
source

Source: https://habr.com/ru/post/980564/


All Articles