I need to pass both FormData and JSON object in an ajax call, but I get a 400 Bad Request error.
[artifact:mvn] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value
[artifact:mvn] at [Source: java.io.PushbackInputStream@3c0d58f6; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value
[artifact:mvn] at [Source: java.io.PushbackInputStream@3c0d58f6; line: 1, column: 3]
JS:
var formData = new FormData(form[0]);
//form JSON object
var jsonData = JSON.stringify(jcArray);
$.ajax({
type: "POST",
url: postDataUrl,
data: { formData:formData,jsonData:jsonData },
processData: false,
contentType: false,
async: false,
cache: false,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
success: function(data, textStatus, jqXHR) {
}
});
Controller:
@RequestMapping(value="/processSaveItem",method = RequestMethod.POST")
public @ResponseBody Map<String,String> processSaveItem(
@RequestBody XYZClass result[])
}
There is similar question, jquery sending form data and a json object in an ajax call and I'm trying the same way.
How can I send both FormData and JSON object in a single ajax request?