有没有办法抓住failed to load resource: net::ERR_CONNECTION_REFUSED,我试过:
try {
$.post('',{},function(res) {
}).fail(function (xhr, textStatus, errorThrown) {
xhr.textStatus = textStatus;
xhr.errorThrown = errorThrown;
console.log('fail',xhr);
// how to get the 'ERR_CONNECTION_REFUSED' or anything else as string?
});
} catch(e) {
console.log('catch',e);
}
Run Code Online (Sandbox Code Playgroud)
失败函数可以捕获,但我没有得到有关错误的信息,它是:
或者其他什么..问题是,如何得到那种错误?
连接到不存在的Web套接字服务器会导致大量错误记录到控制台,通常是调整... net::ERR_CONNECTION_REFUSED.
任何人都有想法让hackaround沉默这个输出?XMLHttpRequest如果服务器不可访问,它将产生相同的详细错误输出,因此将无法工作.
这里的目标是测试服务器是否可用,如果它是连接到它,否则使用回退,并执行此操作而不会通过错误输出向控制台发送垃圾邮件.