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)普通方式的的提交
随机推荐
- ES6 数值
数值的表示 二进制表示法新写法: 前缀 0b 或 0B . console.log(0b11 === 3); // true console.log(0B11 === 3); // true 八进制表 ...
- js的字符串代码库及讲解
1.字符串操作 1.1去除字符串空格 元字符 : \s:空格或者空白等 ^ : 限定开始位置 => 本身不占位置 $ : 限定结束位置 => 本身不占位置 | : 或者 () : 分组代表 ...
- Centos7.1环境下搭建BugFree
环境准备: 系统 配置 IP Centos7.1 1核2G+60GB硬盘 10.10.28.204 1. 安装apache yum install httpd 2. 安装mysql yum inst ...
- SqlServer 行转列,列转行 以及PIVOT函数快速实现行转列,UNPIVOT实现列转行
一 .列转行 创建所需的数据 CREATE TABLE [StudentScores]( [UserName] NVARCHAR(20), --学生姓名 [Subject] NVARCHAR(3 ...
- java框架之SpringBoot(11)-缓存抽象及整合Redis
Spring缓存抽象 介绍 Spring 从 3.1 版本开始定义了 org.springframework.cache.Cache 和 org.springframework.cache.Cache ...
- iot-web增加apis-namespace组件
1 文件夹复制 apis 2 增加 3 增加module
- 【UML】NO.52.EBook.5.UML.1.012-【UML 大战需求分析】- 交互概览图(Interaction Overview Diagram)
1.0.0 Summary Tittle:[UML]NO.52.EBook.1.UML.1.012-[UML 大战需求分析]- 交互概览图(Interaction Overview Diagram) ...
- linux的查找命令 find whereis locate
Linux 有三个查找文件的命令:find, whereis, locate 其中find 不常用,whereis与locate经常使用,因为find命令速度较慢,因为whereis与locate是利 ...
- web前端学习历程--跨域问题
一.同源策略 一个页面的ajax只能获取这个页面相同源(协议.域名.端口号都必须相同)的数据. 二.jsonp方法 1.json和jsonp JSON(JavaScript Object Notati ...
- Vue学习1:实例及生命周期
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...