从HTML表单中获取字段,并使用JQuery/Javascript将它们发送给Servlet的最佳方法是什么?
What is the best way to get the fields from a HTML form, and send them to a Servlet using JQuery/Javascript?
使用jQuery,我找到了这样的解决方案:
$("#submit").click(function () {
alert($('form1').serialize());
$.post("submitForm", $("form1").serialize(), function (result) {
if (result == "success") {
alert("Record added!");
} else {
alert("Could not add Record!");
}
});
});
这是我上面描述的方法的完整HTML,我试图找到从HTML表单中获取数据并将其发送到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>
试试这个-
$(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!");
}
});
});
});
相关文章:
- 这是什么 ==- javascript 运算符
- 我的单元测试选项是什么
- 打破承诺链的好方法是什么
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Javascript中的空白是什么
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- 在JavaScript中拆分日期字符串的更好方法是什么
- 将jQuery.ech()方法转换为本地JavaScript抽象的最佳方法是什么
- 处理浮点错误的最佳方法是什么
- javascript导入的最佳实践是什么
- 基于窗口宽度jquery的函数的替代方法是什么
- 在ng重复循环中显示条件内容的最佳方式是什么
- 我的客户端选项是什么
- 这是什么“;要求“;事情
- 未捕获的类型错误:topFrame.window.changeSelectedBarStyle不是函数,原因是什么
- 实现比较方法的最佳实践是什么;s的比较类型是在运行时选择的
- @@(“at at”)在ES6 JavaScript中是什么意思
- knex:根据结果创建数组的合适方法是什么
- Android,TCP,Servlet - 无需外部库即可进行来回通信.标准有效的方法是什么
- 从HTML表单中获取字段,并使用JQuery/Javascript将它们发送给Servlet的最佳方法是什么?