I am using the following html code which calls the servlet and uploads the file correctly
<html>
<body>
<h3>File Upload:</h3>
Select a file to upload:
<form action="Upload" method="post" enctype="multipart/form-data" id="mainForm">
<div id="upload">
<input type="file" name="file" id="file" size="50" multiple/>
</div>
<input type="submit" id="action" value="Upload File" />
</form>
</html>
But when i serialize the form details and send this request in ajax format the request content is not available in the servlet…
$.ajax({
type: "POST",
url: "UploadServlet",
contentType: "multipart/form-data; charset=UTF-8; boundary=---------------------------" + boundary,
data: $("#mainForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert("ajax response data"+data); // show response from the php script.
}
});
In my servlet there is need of processing the request and from that only the files has to get uploaded is obtained…..
but using ajax request doesn’t return any form elements to the servlet
Can anyone suggest how this can be done with ajax request.
Hint:
I try to use the following parameters in the ajax request but it is not working
cache:false,
contenttype:false,
processData:false
It is not possible with AJAX request use Iframe it may useful.