1

I want to submit a form using ajax javascript and get parameter values by element name in the servlet? How can I do that without appending it to url while calling through ajax code?

Please guide.

Thanks.

1 Answers1

-1

Using POST instead GET

using jquery with the method ajax, you have to put your form into a json object

if your form is like this

<form id="form1">
....
<input id="idvar1" type="text" name="var1">
<input id="idvar2" type="text" name="var2">
</form>

you can use ajax method like this:

var data = {'var1': $(#idvar1).val(), 'var2': $(#idvar2).val()};
// or you can simply make
// var data = $("#form1").serialize()
$("#form1").submit(function() {
  $.ajax({
    type: "POST",
    url: url,
    data: data /* here you will send the data of your form */
  });
});

here more info about $.ajax http://api.jquery.com/jQuery.ajax/

and here more about POST https://en.wikipedia.org/wiki/POST_(HTTP)

Francisco Lavin
  • 928
  • 1
  • 8
  • 14