简体   繁体   English

Javascript try-catch无法捕获“无法加载资源:net :: ERR_CONNECTION_RESET”

[英]Javascript try-catch doesn't catch 'Failed to load resource: net::ERR_CONNECTION_RESET '

I have a multiple file uploader but while it's uploading sometimes 1 out of 10 files doesn't make it and it returns a Failed to load resource: net::ERR_CONNECTION_RESET in chrome console. 我有一个多文件上传器,但有时上载10个文件中的1个没有成功,并且在chrome控制台中返回Failed to load resource: net::ERR_CONNECTION_RESET I tried to catch it with the try-catch, but it acts as if no error occurred. 我试图用try-catch捕获它,但它的行为好像没有发生错误。 What am I doing wrong? 我究竟做错了什么?

var ajax = new XMLHttpRequest();
ajax.open("POST", "/multiFileUploadHandler.php");
try {
    ajax.send(formdata);
} catch (err) {
    alert('Error: '+err);
}

This is likely because it is async. 这可能是因为它是异步的。 Try catching this with an onerror event handler. 尝试使用onerror事件处理程序捕获该事件。

ajax.onerror = function(error) {
    // handle error
};

edit: corrected syntax. 编辑:更正的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载资源:net::ERR_CONNECTION_RESET in angular - Failed to load resource: net::ERR_CONNECTION_RESET in angular JavaScript获取请求错误:无法加载资源:net :: ERR_CONNECTION_RESET - JavaScript get request error: Failed to load resource: net::ERR_CONNECTION_RESET 无法加载资源:net :: ERR_CONNECTION_RESET node js server - Failed to load resource: net::ERR_CONNECTION_RESET node js server 无法加载资源:https://www.google-analytics.com/ga.js中的net :: ERR_CONNECTION_RESET - Failed to load resource: net::ERR_CONNECTION_RESET in https://www.google-analytics.com/ga.js try-catch不适用于XMLHTTPRequest - try-catch doesn't work with XMLHTTPRequest redux-saga catch无法加载资源:net :: ERR_CONNECTION_REFUSED - redux-saga catch Failed to load resource: net::ERR_CONNECTION_REFUSED net::ERR_CONNECTION_RESET, Uncaught (in promise) TypeError: Failed to fetch - net::ERR_CONNECTION_RESET, Uncaught (in promise) TypeError: Failed to fetch Javascript 套接字(失败:WebSocket 握手期间出错:net::ERR_CONNECTION_RESET) - Javascript Sockets (failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET) 在JavaScript中使用try-catch - Use of try-catch in JavaScript JavaScript try-catch无效 - JavaScript try-catch not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM