【问题标题】:How to get jqXHR object from script request that is loaded from <script> tag inside <head>如何从 <head> 中的 <script> 标记加载的脚本请求中获取 jqXHR 对象
【发布时间】:2016-07-28 06:55:02
【问题描述】:

jQuery 的 getScript() 在加载脚本时返回 jqXHR 对象。 当脚本从位于 head 标签内的脚本标签加载时,有没有办法获取 jqXHR 对象?

function makeScript(url){    
    script = document.createElement("script");
    script.src = url;
    //when this line is executed the script will be loaded by the browser
    //how to get the jqxhr object
    document.head.appendChild(script); 
}

【问题讨论】:

  • 没有。 XHR 不与附加的脚本元素一起保存,被请求的脚本也不知道正在发出的请求
  • 这里是 jquerys getScript
  • @BenG +1 为我指明了正确的方向。如链接中所述,我将document.head.appendChild(script); 替换为 $.get。
  • 发现另一个问题,无法调试脚本,因为使用 $.get 加载的脚本没有显示在 CDT 源选项卡中

标签: javascript jquery html xmlhttprequest


【解决方案1】:

不,因为没有。浏览器本机处理所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多