Reputation: 959
I need some help in writing the controller part of the action responsible for receiving the POST request and processing the same..
Client side:
jQuery(function($) {
$("#addPost").submit(function(event) {
alert('addPost');
event.preventDefault();
var $form = $( this );
var url = $form.attr('action');
$.post(url , $("#addPost").serialize(),
function (data ) {
alert("success");
});
});
});
#addPost
is a form and the serialized form data looks like this:
post.type=new&post.title=yyy&post.body=newpost&post.weight=12
On Form click, I can see that the call goes to the post method on the controller. I tried receiving as Map , but it came up as null.
Server Side
public class Application extends Controller {
....
public static void addPost(Map<String, String> req) {
//req is null
}
}
Upvotes: 1
Views: 686
Reputation: 3490
Yoyr addPost controller method is expecting an HTTP (GET/POST) parameter called req, but your params are called post.type, post.title, post.body and post.weight.
Upvotes: 1