Home » Php » javascript – Using $.getScript (jquery): code is not executed

javascript – Using $.getScript (jquery): code is not executed

Posted by: admin July 12, 2020 Leave a comment


I am working on updating my website, which now uses an AJAX engine. My engine works well, up-to-hand for some reason some pages do not execute javascript, let me explain: when the anchor change I use $.get for data recovery. The pages have this structure:

<!--there's the page's content-->

It appears reload the page solves the problem, but i don’t understand what is different. In the previous code, the engine runs successfully, reloaded or not:


In addition, a php generated script contains user’s current state under an Object form:

    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 is successful, but the user object is not changed. The script, however, has yet been modified. And it don’t works from console too.

The update is currently online at v2.wawolf.com, you’ll find everything you need.
Hotlink: Engine’s code

How to&Answers:

I just solved my problem: when all document is loaded, $(function(){}) will not work again, so calling a script which uses $(function(){}) will no get run. I removed it from all my secondary-called scripts and now all works perfectly!


it might just be a loading order issue.

try encapsulating the JS loading in an onload function

    //get script loads here 


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

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