Hi I'm trying to send Ajax request to Spring MVC controller and map it to Java class accordingly:
public class Person implements Serializable {
private MutableLong Id = new MutableLong();
@NotEmpty
@Size(min = 1, max = 50)
String FirstName=null;
@NotEmpty
@Size(min = 1, max = 50)
String LastName=null;
public Person(){}
public long getId(){
return this.Id.longValue();
}
//getters and setters
}
then I have javascript which sends AJAX request:
function loadXMLDoc(){
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("POST","/authenticate.dlp", true);
xmlHttp.setRequestHeader('Content-Type', 'application/json');
param = '{\"FirstName\"=\"test\",\"LastName\"=\"test2\"}';
xmlHttp.send(param);
}
and then the controller itself:
@RequestMapping(value="/authenticate.dlp",method = RequestMethod.POST)
@ResponseBody
public String getAjax(@RequestBody Person person){
Set<ConstraintViolation<Person>> failures = validator.validate(person);
if(!failures.isEmpty())
//......
}
It look like ne response from Server. If I'm using Fddler i se ethe following response from the server
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().
What Im I doing wrong?
Tank you in advance.