Gopal SA
Gopal SA

Reputation: 959

play! framework 1.2.5 | Receiving and processing jquery ajax request on the Action controller

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

Answers (1)

palako
palako

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

Related Questions