简体   繁体   English

使用ajax将文件上传到服务器上传目录。 图片未上传到上传目录; 收到连接重置错误

[英]File upload to server upload directory by using ajax. The image is not getting uploading to upload directory; getting the error of connection reset

File upload to server upload directory by using ajax the image is not getting uploading to the upload directory. 通过使用ajax将文件上传到服务器上传目录,图像未上传到上传目录。 I'm getting the error of "connection reset". 我收到“连接重置”错误。 Please let me know the mistake I am doing in the below code. 请让我知道我在以下代码中所做的错误。 I created the upload directory in the site root in the netbeans IDE. 我在netbeans IDE的站点根目录中创建了上载目录。

<body>       

 <form method="post" action= "upload">           
     <input type=file id="media" name=media>
    <input type="submit">         
 </form>
 </body>    

jquery code to upload the image to upload folder. jQuery代码将图像上传到上传文件夹。

 $(document).ready(function(){      
  $(form).on('submit',function(event){

    event.preventDefault();        
    var formData = new FormData($('form')[0]);

   $.ajax({

       type:'POST',         
       url:'upload',
       data :formData,        

       processData:false,        
       contentType:false,

       success:function()          
       {
            alert('File uploaded');        
       }       
     });            
    });       
}); 

Move your var formData = new FormData($('form')[0]); 移动您的var formData = new FormData($('form')[0]); outside of $(document).ready(function(){ $(document).ready(function(){
something like the below added lines 类似于以下添加的行
var formData = new FormData($('form')[0]); $(document).ready(function() { $("#formID").on('submit', function(event) {

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

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