Is the callback on jQuery's getScript() unreliable or am I doing something wrong?

后端 未结 11 1298
Happy的楠姐
Happy的楠姐 2020-12-03 03:17

I\'m using the following bit of script to load another one:

$.getScript(\"CAGScript.js\", function () {
    try {
        CAGinit();
    } catch(err) {
              


        
11条回答
  •  囚心锁ツ
    2020-12-03 03:57

    I think you can start by checking testStatus of the callback function to make sure that the script was really loaded. Callback function has two parameters, more defails on those you can find on jQuery Docs

    $.getScript("CAGScript.js", function (data, textStatus) {
        if (textStatus === "success") {
            try {
                CAGinit();
            } catch(err) {
                console.log(err);
            }
        } else {
            console.log("script not loaded");
        }
    });
    

提交回复
热议问题