码迷,mamicode.com
首页 > 其他好文 > 详细

解决XMLHttpRequest的timeout在firefox<12版本无效

时间:2014-07-22 22:32:16      阅读:383      评论:0      收藏:0      [点我收藏+]

标签:blog   http   java   os   io   cti   

XMLHttpRequest的timeout在firefox<12 版本无效的,可以重写XMLHttpRequest的timeout对象

// snip

to = function() {
    attempt++;
    if( attempt < 5)
        send();
    else if( !silent) {
        console.log("Request Timeout\nFailed to access "+url);
    }
};

// snip

var send = function() {
    if( loader && attempt != 0) {
        loader.children[0].firstChild.nodeValue = "Error... retrying...";
        loader.children[1].firstChild.nodeValue = "Attempt "+(attempt+1)+" of 5";
    }
    a = new XMLHttpRequest();
    a.open("POST","/ajax/"+url,true);
    a.onreadystatechange = rsc;
    setTimeout(function () {     /* vs. a.timeout */
        if (a.readyState < 4) {
            a.abort();
        }
    }, 5000);
    a.onabort = to;              /* vs. a.ontimeout */
    a.setRequestHeader("Content-Type","application/json");
    a.send(data);
    console.log(‘HTTP Requesting: %s‘, url);
};

  

解决XMLHttpRequest的timeout在firefox<12版本无效,布布扣,bubuko.com

解决XMLHttpRequest的timeout在firefox<12版本无效

标签:blog   http   java   os   io   cti   

原文地址:http://www.cnblogs.com/kennyhr/p/3860999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!