admin管理员组

文章数量:1530043

测试时间:2019/02/26

MacOS 环境下,timeout在各浏览器默认值为(以下浏览器都为当前时间最新版本)

chrome 72.x 为4min

safari 12 为8min

firefox 65 貌似没有超时时间

测试代码

Document

query

const ajax = (url = '/api/timeout') => {

const xhr = new XMLHttpRequest();

//设置xhr请求的超时时间

xhr.timeout = 60 * 5 * 1000;

xhr.responseType = "text";

xhr.open('GET', url, true);

xhr.onload = function(e) {

if(this.status == 200 || this.status == 304){

console.log('请求完毕')

if(loopId) {

clearInterval(loopId)

}

}

console.log(e)

}

xhr.send()

}

const queryBtn = document.querySelector('#queryBtn')

const time = document.querySelector('#time')

loopId = null

queryBtn.addEventListener('click', (event) => {

ajax()

const startTime = new Date()

loopId = setInterval(() => {

const s = parseInt((new Date() - startTime) / 1000)

time.innerHTML = s + ' s'

}, 500)

})

var express = require('express');

var app = express();

var http = require('http').Server(app);

var bodyParser = require('body-parser');

app.use(bodyParser());

app.use(express.json());

app.use(express.static(__dirname + ''));

app.get('/', function(req, res){

res.render('index', {});

// res.send('

Welcome Realtime Server

');

});

app.get('/api/timeout', function(req, res){

setTimeout(() => {

res.send("i don't see a lot of PUT requests anymore")

}, 60 * 10 * 1000)// 这里设置服务器的响应时间

});

http.listen(3004, function(){

console.log('http://127.0.0.1:3004');

});

且在chrome设置timeout为5min没有用,在4min时已经提示请求失败

上面这张是chrome,下面是Safari

本文标签: 多久时间浏览器ajaxchrome