0

I have a jsp which contains a form, I want to send this form data to a servlet with ajax, and then in success to get some data from servlet and display it in my jsp.

this is my form :

/WEB-INF/quiz.jsp

<form name="example-1" id="wrapped" action="Resultat" method="POST" >
//Inputs
<button type="submit" class="submit" id="calculer">Calculer mon résultat</button>
</form>

And this is the JavaScript :

/WEB-INF/inc/js/functions.js

$("#wrapped").submit(function(event){

    event.preventDefault();

    var form        = $(this),
        formData    = new FormData(this),
        url         = form.attr('action');

    $.ajax({
        url     : url,
        type    : 'POST',
        data    : formData,
        success : function(data){
            $("#resultat").html(data);
        } 
    });

});

My question is : How can I get the values in my sevlet to manipulate them ? and then how can I define that data attribute in the success in my sevlet ?

Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191

1 Answers1

0
$("#wrapped").submit(function(event){
event.preventDefault();
var form        = $(this),
    formData    = new FormData(this),
    url         = form.attr('action');

$.ajax({
    url     : url,
    type    : 'POST',
    data    : formData,
    success : function(data){
        $("#resultat").html(data);
         // After getting the data again give a Ajax request to a servlet
          $.ajax({
                 url     : url,
                 type    : 'POST',
                 success : function(data){
                       // display data in jsp
                   } 
      });


    } 
});

});

Srikanth Venkatesh
  • 2,812
  • 1
  • 20
  • 13