jQuery中防止表单提交两次的方法
遇到过表单提交两次的情况,做个记录;
解决场景:首先是表单验证,其次是防止多次提交表单;
jQuery中插件:validate_submitHandler_plugin,具体的可以使用关键字搜索;
使用方法:首先在前端定义form表单,然后jQuery来处理验证和提交:
<form id="application-form" class="form-horizontal">
<div class="rds panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">源表信息</h3>
</div>
<div class="panel-body">
<div class="form-group">
<label for="source-cluster" class="col-sm-2 control-label"><span class="required-field">*</span> 源集群:</label>
<div class="col-sm-8 control-section">
<input id="source-cluster" name="sourceCluster" class="form-control" value="${cluster.name}" readonly>
</div>
</div>
<div class="form-group">
<label for="source-schema" class="col-sm-2 control-label"><span class="required-field">*</span> 源数据库:</label>
<div class="col-sm-8 control-section">
<select id="source-schema" name="sourceSchema" class="form-control"></select>
</div>
</div>
</div>
</div>
<div class="rds panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">目标表信息</h3>
</div>
<div class="panel-body">
<div class="form-group">
<label for="target-cluster" class="col-sm-2 control-label"><span class="required-field">*</span> 目标集群:</label>
<div class="col-sm-8 control-section">
<select id="target-cluster" name="targetCluster" class="form-control"></select>
</div>
</div>
<div class="form-group">
<label for="target-schema" class="col-sm-2 control-label"><span class="required-field">*</span> 目标数据库:</label>
<div class="col-sm-8 control-section">
<input type="text" id="target-schema" name="targetSchema" class="form-control" placeholder="database number">
</div>
</div>
</div>
</div>
<button id="btn-submit" type="submit" class="btn btn-primary" disabled>提交</button>
</form>
$("#application-form").validate({
rules: {
sourceCluster: "required",
sourceSchema: "required",
targetCluster: "required",
targetSchema: "required",
},
submitHandler: function() {
const sourceCluster = $("#cluster-name").val();
const sourceDatabase = $("#source-schema").selectpicker("val");
const targetCluster = $("#target-cluster").selectpicker("val");
const targetDatabase = $("#target-schema").val(); handleSubmit({sourceCluster, sourceDatabase, targetCluster, targetDatabase});
}
});
其中会遇到的问题,可以参考我在Stack Overflow上的回答:
https://stackoverflow.com/questions/23693658/jquery-validate-submits-form-twice
jQuery中防止表单提交两次的方法的更多相关文章
- MVC中处理表单提交的方式(Ajax+Jquery)
MVC中处理表单有很多种方法,这里说到第一种方式:Ajax+Jquery 先看下表单: <form class="row form-body form-horizontal m-t&q ...
- 在Action中获取表单提交数据
-----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...
- ajaxSubmit 页面生成的html 中含有表单提交表单方式
$("#form_title").ajaxSubmit({ //页面生成的html 中含有表单提交表单方式 dataType: "json", success ...
- koa 基础(十)原生node.js 在 koa 中获取表单提交的数据
1.app.js // 引入模块 const Koa = require('koa'); const router = require('koa-router')(); /*引入是实例化路由 推荐*/ ...
- form表单提交的几种方法
form表单提交的几种方法 <form id="myform" name="myform" method="post" onsubmi ...
- jQuery判断 form表单提交时一些文本框的判断
一: form表单提交时如果表单里有input标签为空那么不提交form表单. <head> <script type="text/javascript"> ...
- jQuery补充之jQuery扩展/form表单提交/滚动菜单
jQuery扩展 为了避免重复造轮子,能高效使用别人的代码,所以有了扩展. jQuery扩展有两种方式: 自执行函数方式 定义函数,并执行函数. 自执行函数: (function(jq){ jq.ex ...
- EasyUI中在表单提交之前进行验证
使用EasyUi我们可以在客户端表单提交之前进行验证,过程如下:只需在onSubmit的时候使用return $("#form1").form('validate')方法即可,E ...
- asp.net.mvc 中form表单提交控制器的2种方法和控制器接收页面提交数据的4种方法
MVC中表单form是怎样提交? 控制器Controller是怎样接收的? 1..cshtml 页面form提交 (1)普通方式的的提交
随机推荐
- Java加载dll或so库文件的路径 java.library.path
1. Java的System.load 和 System.loadLibrary都可以用来加载库文件 2.例如你可以这样载入一个windows平台下JNI库文件: System.load(&q ...
- 【托业】【新东方托业全真模拟】TEST05~06-----P5~6
credit A with B 把A归功于B present A with B 给A赠送B proofread thoroughly 彻底地校对:exclusively 专门地:独占地:apparen ...
- async await 的使用。 其实就是和then一样,只不过改变了链式写法
这样写显得更加舒服.
- oracle 新建用户后赋予的权限语句
grant create session,resource to itsys; grant create table to itsys;grant resource to itsys;grant cr ...
- python中列表中元素的增删改查
增: append : 默认添加到列表的最后一个位置 insert : 可以通过下标添加到列表的任意位置 extend: a.extend[b] --将b列表的元素全加入到列表b中 删; remove ...
- Vue.js使用Leaflet地图
参考:https://blog.csdn.net/Joshua_HIT/article/details/72860171 vue2leaflet的demo:https://github.com/KoR ...
- netframework webapi exceptionless
1.webapi项目 添加nuget exceptionless webapi 2.在exceptionless server端添加项目,注意key 3.修改api项目的webconfig &l ...
- DevOps“五宗罪”,这样向DevOps过渡注定会失败
云计算提供的速度响应.敏捷性和规模效应,契合了如今不断变化的数字商业环境.企业基于最新的IT技术,重构IT架构,加速产品创新和服务交付的速度,从而提高运营效率和市场占有. 不过,企业IT管理者在利用云 ...
- CentOS 7 MariaDB-MMM
MariaDB-MMM高可用群集 1.MySQL-MMM概述 MMM(Master-Master replication manager for MySQL)是一套支持双主故障切换和双主日常管理的脚本 ...
- 第一篇——Struts2的工作原理及HelloWorld简单实现
Struts2工作原理: 一个请求在Struts框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求: 2.这个请求经过一系列的过滤器(Filter): 3.接着F ...