Spring Portlet Jquery Ajax post to Controller

对着背影说爱祢 提交于 2019-12-02 08:54:55

You don't need to work with JSON data at all.

First, avoid stringification of dataObject:

var dataObject = {...}; // no JSON.stringify call

Second, remove contentType: 'application/json' as it doesn't make sense in this case.

With dataObject being a key/value pair and default contentType, the POST request will be constructed correctly.

To handle both click and submit events, I suggest to jQuery click and submit methods:

$("#submit").click(function (event) {
    addNew();
    event.preventDefault();
});
$("#submit").submit(function (event) {
    addNew();
    event.preventDefault();
});

I've created a fiddle for the question.

See jQuery.ajax documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!