Waiting for dynamically loaded script

前端 未结 6 1744
忘了有多久
忘了有多久 2020-11-30 08:28

In my page body, I need to insert this code as the result of an AJAX call:

    

Loading jQuery

6条回答
  •  遥遥无期
    2020-11-30 08:51

    It is pretty safe. Historically,

    Using jQuery

    However, it's probably a better idea it use dynamic script tag insertion instead of pushing this as HTML string into the DOM. Would be the same story

    var scr  = document.createElement('script'),
        head = document.head || document.getElementsByTagName('head')[0];
        scr.src = 'scripts/jquery/core/jquery-1.4.4.js';
        scr.async = false; // optionally
    
    head.insertBefore(scr, head.firstChild);
    

提交回复
热议问题