0

i am new to play and javascript. I was trying to submit form with ajax. initially i had

     @form(action = routes.Application.save(1,2), 'enctype -> "multipart/form-data") {
     @inputText(businessForm("name"), '_label -> "Business name")
     } 

in routes file i have POST /businessSave controllers.Application.save(c:Int, r:Int)

it was working fine with full page load... i tried to make it ajax as below

   <form id="xk" action="/businessSave" method="post" >
   @inputText(businessForm("name"), '_label -> "Business name")
   </form?

and added javascript

      $("#xk").submit(function(event) {
event.preventDefault();

    jsRoutes.controllers.Application.save(1,2).ajax({
data : $("#xk").serialize(),
    success : function(data) {
     $("#main").html(data);
    }

   });

i also tried with

    $('#xk').submit(function(event) {
event.preventDefault();
var c = $("#c").val();
var r = $("#r").val();
var url1 = "/businessSave?c="+c+"&r="+r;

$.ajax({
    url: url1,
    type: 'post',
    enctype:'multipart/form-data',
    data: $("#xk").serialize(),
    success: function(data) {
        $("#main").html(data);
    }
    });

   });

but i am getting bad request exceptions..

please let know how to submit a play form with ajax

dsr301
  • 759
  • 3
  • 7
  • 21
  • 1
    I am getting error :For request 'POST /businessSave?c=1&r=2' [Missing boundary header] – dsr301 Sep 21 '13 at 17:30
  • this is failing only in case of multipart/form-data. where i have on server side def save() = Action(parse.multipartFormData) . I removed the image and parse.multipartFormData on server side and its working fine. But still i want to know how to make it work even with file – dsr301 Sep 23 '13 at 08:42
  • Worked with the solution provided here : http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery/8758614#8758614 – dsr301 Sep 24 '13 at 11:04

0 Answers0