jQuery.getScript() fails to load function

前端 未结 2 1510
迷失自我
迷失自我 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 18:52

    readCookie is undefined because readCookie is not global; it is visible only within the document.ready function scope in mymy.js.

    Make the function global by removing the document.ready wrapper.

提交回复
热议问题