$(document).ready(function () {
$("#sendmail").click(function (event) {
//stop submit the form, we will post it manually.
event.preventDefault();
// for (i = 0; i < mails.length; i++) {
// Get form
var form = $('#fileUploadForm')[0];
// Create an FormData object
var data = new FormData(form);
// If you want to add an extra field for the FormData
data.append("email12", mails[0]);
// disabled the submit button
$("#btnSubmit").prop("disabled", true);
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "EmailController",
data: data,
processData: false,
contentType: false,
cache: false,
timeout: 600000,
success: function (data) {
$("#result").text(data);
console.log("SUCCESS : ", data);
$("#btnSubmit").prop("disabled", false);
},
error: function (e) {
$("#result").text(e.responseText);
console.log("ERROR : ", e);
$("#btnSubmit").prop("disabled", false);
}
});
// }
});
});
在此代码中使用event.preventDefault()它成功运行但我不想阻止按钮的默认操作...如果我不使用event.prevntDefault()方法然后我得到错误
java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
at org.apache.catalina.connector.Request.parseParts(Request.java:2793)
at org.apache.catalina.connector.Request.parseParameters(Request.java:3083)
at org.apache.catalina.connector.Request.getParameter(Request.java:1151)
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:384
如何解决此问题。