I want to submit my jsp using jquery ajax form submit. While submitting browser showing "Content type 'application/json;charset=utf-8' not supported"
var form = $('#encryptForm');
$(function() {
$('button[type=submit]').click(function(e) {
//Prevent default submission of form
e.preventDefault();
$.post({
url : 'encrypt',
dataType: "json",
contentType: "application/json; charset=utf-8",
data : form.serialize(),
success : function(res) {
console.log(res)
}
})
});
});
<form id="encryptForm" name="encryptForm" method="POST">
<fieldset>
<legend>User Fields</legend>
<p>
<textarea rows="4" cols="50" id="encryptData" >{"mid":"MID-NehoT","message":"hello"}</textarea>
</p>
<p>
<button type="submit">Submit</button>
</p>
</fieldset>
</form>
@RequestMapping(value = "/encrypt", method = RequestMethod.POST)
public Response post(@RequestBody Request request) {
return null;
}
@JsonIgnoreProperties(ignoreUnknown = true)
public class Request {
private String mid;
private String message;
@JsonCreator
public Request(String mid, String message) {
this.mid = mid;
this.message = message;
}
public String getMid() {
return mid;
}
public void setMid(String mid) {
this.mid = mid;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}