I have create a page and submit a post request to server, the jquery code like this
jquery codeļ¼
$("#button").click(function() {
var book = {
name: "book123",
isbn: "123456"
};
$.post("book/add", book, function(data) {
console.debug(data);
});
});
Spring controller code:
@RequestMapping(value = "/add",method = RequestMethod.POST)
public @ResponseBody String addBook(
@RequestBody Book book, HttpServletResponse response) throws Exception {
book.setRanking(DEFAULT_RANKING);
Book returnbook = bookService.createBook(book);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(returnbook);
}
But it has error, in firebug, I get this error code:
NetworkError: 415 Unsupported Media Type - /book/add
the requst header information is this:
Accept / Accept-Encoding gzip, deflate
Accept-Language en;q=0.8,en-us;q=0.5
Content-Length 24
Content-Type application/x-www-form-urlencoded; charset=UTF-8
DNT 1
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
X-Requested-With XMLHttpRequest
I think the content-type is not correct as in bold. How to resolve this issue? Thanks!