简体   繁体   English

jQuery 1.4.2 XHR请求网:: ERR_CONNECTION_RESET

[英]JQuery 1.4.2 XHR request net::ERR_CONNECTION_RESET

I'm backend developer and pretty new in Javascript. 我是后端开发人员,并且是Java语言中的新手。 I'm trying to upload files with old JQuery version (1.4.2), because there is no way to change it on current project. 我正在尝试使用旧的JQuery版本(1.4.2)上传文件,因为无法在当前项目中对其进行更改。

This code works good on ANY JQuery version >= 1.5 这段代码在> = 1.5的任何jQuery版本上都能正常工作

$('#uploadform').submit(function(e) {
    var formData = new FormData(this);
    $.ajax({
       type:'POST',
       url: '/uploader',
       data:formData,
       xhr: function() {
           var myXhr = $.ajaxSettings.xhr();
           if(myXhr.upload){
               //
           }
           return myXhr;
       },
       cache:false,
       contentType: false,
       processData: false,

       success: function(data){
           //
       },

       error: function(data){
           //
       }
   });
});

Each time a run it on JQuery 1.4.2, I have this error in Chrome (and other browsers): POST http://localhost:8080/uploader net::ERR_CONNECTION_RESET in jquery-1.4.2.js:5252 每次在JQuery 1.4.2上运行它时,我在Chrome(和其他浏览器)中都会出现此错误:jQuery POST http://localhost:8080/uploader net::ERR_CONNECTION_RESETjquery-1.4.2.js:5252

Is there a way to fix it without JQuery version change? 有没有一种方法可以在不更改JQuery版本的情况下进行修复?

UPD UPD

Here is my <head> section in html 这是我在HTML中的<head>部分

<head>
<meta charset="UTF-8">
<title>Remedy Uploader</title>
<link type="text/css" rel="stylesheet" href="style.css" media="screen"/>
<script type='text/javascript' src="https://code.jquery.com/jquery-1.4.2.js"></script>
<script type='text/javascript' src="script.js"></script>

var oldXHR = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function() {
    var xhr = oldXHR();
    if(xhr instanceof window.XMLHttpRequest) {
        xhr.upload.addEventListener('progress', on_progress, false);
        xhr.upload.addEventListener('load', on_loaded, false);
        xhr.addEventListener('abort', on_abort, false);
    }
    return xhr;
};

$.ajax({
    xhr: function() {
        var xhr = jQuery.ajaxSettings.xhr();
        if(xhr instanceof window.XMLHttpRequest) {
            xhr.upload.addEventListener('progress', on_progress, false);
            xhr.upload.addEventListener('load', on_loaded, false);
            xhr.addEventListener('abort', on_abort, false);
        }
        return xhr;
    }
});

check below URL 检查以下URL

How to get pure XMLHTTPRequest object in jQuery 1.5? 如何在jQuery 1.5中获取纯XMLHTTPRequest对象?

First you should try to comment all code at http://localhost:8080/uploader and just print a hello message. 首先,您应该尝试在http:// localhost:8080 / uploader上注释所有代码,然后仅打印hello消息。 Then test it in browser, It must be working. 然后在浏览器中测试它,它必须正在工作。 If it does not work the fix it first, but when works then try following request as it is 如果无法解决问题,请先解决,但在解决问题后,请尝试按照以下要求进行操作

with jquery 1.4.2 you can use same ajax request as it is used today 使用jQuery 1.4.2,您可以使用与今天相同的ajax请求

$.ajax({
    type: "POST",
    //I commented followin gintentionally, you should check the 
    // before un-commenting this line
    //data : formData code 
    url: 'http://localhost:8080/uploader',
    success: function(data){alert(data)},
    error: function(err){ alert(er.responseText)};
});

Off course you will face no error 当然,您将不会遇到任何错误

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM