【发布时间】: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