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

后端 未结 11 1263
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:50

    I noticed the same issue with FF 3.6.

    A solution is to load the script synchronously.

    As mentioned in jQuery's documentation, getScript is shorthand for:

    $.ajax({
      url: url,
      dataType: 'script',
      success: success
    });
    

    Everything works fine if I use the following instead of getScript:

    $.ajax({
      url: url,
      dataType: 'script',
      success: success,
      async: false
    });
    

提交回复
热议问题