【发布时间】:2021-01-01 17:37:04
【问题描述】:
我正在使用 XMLHttpRequest 异步发出 http 请求:
xhr.open(method, uri, true);
当我发送something:
xhr.send(something)
当服务器宕机时,会抛出如下错误:
net::ERR_CONNECTION_REFUSED
如何捕捉和处理这个错误?标准的try..catch 块不起作用,因为请求是异步的。
提前致谢。
【问题讨论】:
-
你会接受jQuery answers?
-
抱歉,正在寻找原生 JS 答案。
标签: javascript html http xmlhttprequest