Hi I am trying to post 3 things json object and 2 file object but request is not going to controller pls find below code :
java script funtion:
<script type="text/javascript">
function submitAllDetails(){
var jsonObj=[{
name:name,
age:age,
rollno:rollno,
add:add,
}];
var jsonString=JSON.stringify(jsonObj);
alert(jsonString);
var fileInput=document.getElementById("Uploadfile");
var file=fileInput.files[0];
var fd = new FormData();
fd.append("fileUpload",file);
var fileInput1=document.getElementById("Uploadfile2");
var file1=fileInput1.files[0];
var fd1 = new FormData();
fd1.append("fileUploadnew",file1);
$.ajax({
url:contextPath +"/submitAllInfo",
type:"POST",
contentType: "application/json; charset=utf-8",
data: {jsonString:"jsonString", fd:"fd", fd1:"fd1"},
async: false,
cache: false,
processData:false,
success: function(response){
alert("in success***");
},
error: function(){
alert("error has occured");
}
});
}
</script>
Contorller code :
@RequestMapping(value = "/submitAllInfo", method = RequestMethod.POST)
public @ResponseBody ModelAndView insertAllStepDetails(@RequestParam("jsonString") String jsonString,@RequestParam("fd") CommonsMultipartFile[] fileUpload,@RequestParam("fd1") CommonsMultipartFile[] fileUploadnew){
System.out.println("in submit controller !!!");
return new ModelAndView("success");
}
I doubt the problem with the syntax of the line data: {jsonString:"jsonString", fd:"fd", fd1:"fd1"},
not sure what is the issue it always going in error block.
Any suggestion