[英]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.