最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xmlhttprequest - Javascript try-catch doesn't catch 'Failed to load resource: net::ERR_CONNECTION_RESET &#39

programmeradmin0浏览0评论

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. I tried to catch it with the try-catch, but it acts as if no error occurred. What am I doing wrong?

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

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. I tried to catch it with the try-catch, but it acts as if no error occurred. What am I doing wrong?

var ajax = new XMLHttpRequest();
ajax.open("POST", "/multiFileUploadHandler.php");
try {
    ajax.send(formdata);
} catch (err) {
    alert('Error: '+err);
}
Share Improve this question asked Mar 5, 2014 at 10:35 Matthew AbrmanMatthew Abrman 73110 silver badges18 bronze badges 1
  • usually this error happens when the server's transport detected a error condition and thus it does reset your TCP/IP connection ! :) – Mehdi Maghrouni Commented Mar 26, 2014 at 16:43
Add a ment  | 

1 Answer 1

Reset to default 6

This is likely because it is async. Try catching this with an onerror event handler.

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

edit: corrected syntax.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论