In following code i am submitting form via submit but from javascript and the response is going to other page, is there any way to get that response on same page so that i can replace that content to somewhere using jquery.
// controller side code
@RequestMapping(value = "upload", method=RequestMethod.POST)
public @ResponseBody String upload(HttpServletRequest request, HttpServletResponse response,
@RequestPart("dataFile") MultipartFile file
){ if(file!=null){
//code to upload file and will return 1
return "1";
}
return "0";//otherwise it will return 0
}
Following is html side code
<html>
<script language="Javascript">
function fileUpload(form) {
// Submit the form...
form.submit();
// here if i get that response then i'll be able to put that content somewhere else via jQuery. i dont want response directed on url/upload.
}
</script>
//html code
<!-- index.php could be any script server-side for receive uploads. -->
<form target="upload_iframe" method="post" action="upload" enctype="multipart/form-data" encoding="multipart/form-data">
<input type="file" name="dataFile" id="dataFile" /></br>
<input type="button" value="upload"
onClick="fileUpload(this.form); return false;" >
<div id="uploadShow"></div>
</form>
</html>