使用AJAX上传多个文件 [英] Multiple files upload using AJAX
本文介绍了使用AJAX上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个Web应用程序,并且正在使用多个文件上传功能,但是它不适用于AJAX.对于多个文件上传,我使用了Apache FileUpload,它运行正常,但是在使用Ajax之后,ServletFileUpload.isMultipartContent()返回False.
I'm working on a webapp and I'm using multiple files upload, but it doesn't work with AJAX. For multiple files upload i use the Apache FileUpload which is working perfectly but after using Ajax the ServletFileUpload.isMultipartContent() returns False.
感谢您的帮助
这是我的JSP代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Envoi des fichiers RNP</title>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/fileupload.js"></script>
<link type="text/css" rel="stylesheet" href="css/form.css">
</head>
<body>
<form id="myForm" >
<fieldset>
<legend>Envoi de fichier</legend>
<label for="fichier">Emplacement du premier fichier <span class="requis">*</span></label>
<input type="file" id="fichier" name="fichiers[]" multiple value="<c:out value="${fichier.nom}"/>"/>
<span class="erreur">${form.erreurs['fichier']}</span>
<br />
<br />
<input type="submit" value="Envoyer" id="showTable"/>
<br />
</fieldset>
</form>
<div id="tablediv">
<table cellspacing="0" id="site2G">
<tr>
<th scope="col">CGI</th>
<th scope="col">BSC</th>
<th scope="col">Site Name</th>
<th scope="col">Cells</th>
<th scope="col">EA</th>
</tr>
</table>
</div>
</body>
</html>
和我的AJAX代码:
$(document).ready(function() {$("#tablediv").hide();
$("#myForm").submit(function(event){
event.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
url: "Upload",
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(responseJson) {
if(responseJson!=null){
$("#site2G").find("tr:gt(0)").remove();
var table1 = $("#site2G");
$.each(responseJson, function(key,value) {
var rowNew = $("<tr><td></td><td></td><td></td><td></td><td></td></tr>");
rowNew.children().eq(0).text(value['bsc']);
rowNew.children().eq(1).text(value['sitename']);
rowNew.children().eq(2).text(value['cells']);
rowNew.children().eq(3).text(value['cgi']);
rowNew.children().eq(4).text(value['ea']);
rowNew.appendTo(table1);
});
}
}
});
$("#tablediv").show();}); });
推荐答案
您可以选择第三方插件将多个文件上传到服务器
You can prefer third party plugins to upload your multiple files to server
我将推荐的一些是
他们支持
多个文件上传.
进度栏
文件成功上传后该怎么做
what to do after file has successfully uploaded
图片预览
这篇关于使用AJAX上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文