jQuery.getScript() fails to load function

前端 未结 2 1477
迷失自我
迷失自我 2021-01-26 18:38

I am trying to load a script with a function like:

$.getScript(\'/js/mymy.js\').done(function(){ 
    if(readCookie(\'my_cookie\', \'yes\')){
        /* do sth h         


        
2条回答
  •  生来不讨喜
    2021-01-26 19:07

    From the docs:

    The callback is fired once the script has been loaded but not necessarily executed.

    In other words, you cannot rely on the success function to be called explicitly after the loaded script is executed, e.g., its functions put into the global scope.


    After your edit (which IMO should have been what you posted first) you actually have two issues; as written it's scoped only inside JQ's DOM-ready function.)

提交回复
热议问题