weixin_33695082 2015-07-30 15:44 采纳率: 0%
浏览 165

向getScript()添加超时

I'm using the getScript() JQuery method but could really do with adding a timeout. Some scripts don't come back as failed for a good 6-8 seconds, which is too long.

Is this possible?

I've searched a bit and no solutions have been forthcoming.

Something like:

$.getScript(a + "/myspeed/MySpeedServer/mss/js")
        .done(function() {
            //do stuff
        })
         .fail(function() {
            //do stuff
        });
         .timeout(2000)
  • 写回答

2条回答 默认 最新

  • weixin_33709219 2015-07-30 15:52
    关注

    $.getScript is simply a wrapper around $.ajax(). Hence, you could use $.ajax() with the timeout option as below.

    $.ajax({
        url: url,
        dataType: "script",
        timeout: 2 * 1000
    }).done(function() {
        //do stuff
    })
    .fail(function() {
        //do stuff
    });
    

    A note from the doc: In Firefox 3.0+ only, script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.

    You may also use the abort() method as stated here.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器