java - What is the best way to get the fields from a HTML form, and send them to a Servlet using JQuery/Javascript? -
using jquery i've found solutions such this:
$("#submit").click(function () { alert($('form1').serialize()); $.post("submitform", $("form1").serialize(), function (result) { if (result == "success") { alert("record added!"); } else { alert("could not add record!"); } }); });
here full html of method had described above, im trying find best way data the html form , send servlet "submitform".
<html> <head> <title>myform</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $("#submit").click(function () { alert($('form1').serialize()); $.post("submitform", $("wmform_174835").serialize(), function (result) { if (result == "success") { alert("record added!"); } else { alert("could not add record!"); } }); }); </script> </head> <body> <a href="submitform">myform</a> <form action="submitform" method="post" id="form1"> <input type="text" value="12" name="id"/> <input type="text" value="namethatcomesfirst" name="firstname"/> <input type="text" value="namethatcomeslast" name="lastname"/> <input type=submit id="submit" value="submit"/> </form> </body> </html>
try -
$(document).ready(function(){ $("#submit").click(function () var data = $('#form1').serialize(); alert(data); $.post("submitform", data, function (result) { if (result == "success") { alert("record added!"); } else { alert("could not add record!"); } }); }); });
Comments
Post a Comment