Post form via ajax and get a form object in play framework java Post form via ajax and get a form object in play framework java jquery jquery

Post form via ajax and get a form object in play framework java


Step 1: Rename all private properties to public and remove getter and setter methods. e.g.

private String per1= "off"; to public String per1= "off";

Step 2. Ensure your route file is a GET request

Step 3. Try using basic Jquery ajax to test run.

$("#form-permission").on('submit', function() {   var $this = $(this);   $.ajax({     url: '/url/to/controller',     data: $this.serialize(),     type: 'GET'   });   return false;});

You can always should from GET to POST at your convenience, kindly ensure you change your JQuery and html form method to POST value and also your Playframework routes file to POST.

Hope this works!


Well, the other approach which you are looking for where you want the object instead of Json at the server side --
You can always de-serialize it.Tools like gson and fasterxml json are there and something you should be looking into. This way there is no extra effort in creating the entities you want to persist.
HTH.