0

I have a form in my site sending with post. I have to use the variables in the same page without reload the data. I have this.

     <html>
     <head>
      <meta http-equiv="Content-Type" content="text/html"; charset="ISO-8859-1">
       <title>Ejemplo de carga de datos</title>
       <script src="/Scripts/jquery-1.9.1.js"></script> 

     <script>
  $(function(){ 
     $("#form").submit(function(event){

    var str = $(this).serialize();
    alert(str);



       <% System.out.println(request.getParameter("radioValue00")); %> 
   });
 });
</script>
</head>
 <body>
<h3>Ejemplo de captura de datos</h3>

 <form name="form" id="form"  method="post" enctype="multipart/form-data" >


  Choose one:

  <input type="radio" name="radioValue00" id ="radioValue00S" value="S" required> Yes
   <input type="radio" name="radioValue00" id ="radioValue00N" value="N"> No

    <input type="submit" name="submit" value="Enviar datos" />

     </form>

</body>
</html>



        <% System.out.println(request.getParameter("radioValue00")); %> 
    });
});
</script>

when I alert(str), I see the following:

screenshot of the alert

I can see all the data, so it has been sent, but when try to print it is empty, how can I use it?

clinton3141
  • 4,751
  • 3
  • 33
  • 46
cucuru
  • 3,456
  • 8
  • 40
  • 74
  • Can you show where you using POST? – StealthSpoder Feb 04 '16 at 16:49
  • You're printing the value right in to the middle of your JS `script` block. When the form is submit you'll just see a JS error on the screen because of it. Have you checked in the source to see if a value is there? – Rory McCrossan Feb 04 '16 at 17:00
  • I see when i do alert(str) that the value exists, and its has "S", but when try to print with jsp it prints "null" – cucuru Feb 04 '16 at 17:03

1 Answers1

0

Replace enctype="multipart/form-data" with enctype="application/x-www-form-urlencoded" (or just remove the enctype altogether because enctype="application/x-www-form-urlencoded" is the default anyway)

Note that enctype="multipart/form-data" is useful only when uploading files (and binary dana) but has the unfortunate consequence that request.getParameter always returns null ( Of course, there exist workarounds for this kind of situation)

dsp_user
  • 2,061
  • 2
  • 16
  • 23
  • Thanks! but this is not my problem.If I reload the site I can get the data, my problem is how to use without reload – cucuru Feb 05 '16 at 13:12