当前位置: 首页 > article >正文

Jquery easyui异步提交表单的两种方式

这篇文章分享一下easyui常用的两种表单异步提交的方式。

目录

第一种:利用ajax提交

$.post()

$.ajax()

第二种:使用easyui提供的表单提交方式


首先,准备一个简单的表单,包含三个输入框,在页面引入easyui的js文件。

第一种:利用ajax提交

$.post()

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>easyui提交表单方式1</title>
		<link rel="stylesheet" href="../css/themes/icon.css" />
		<link rel="stylesheet" href="../css/themes/default/easyui.css" />
		<script src="../js/jquery.min.js"></script>
		<script src="../js/jquery.easyui.min.js"></script>
		<script src="../js/easyui-lang-zh_CN.js"></script>
	</head>
	
	<body>
		<form id="ajax_form">
			姓名:<input id="name" />
			年龄:<input id="age" />
			手机号:<input id="phone" />
			
			<button type="button" id="submit"></button>
		</form>
		
		<script>
			$(function(
				$("#submit").click(function() {
					$.post("/xxx/save", {
						name: $("#name").val(),
						age: $("#age").val(),
						phone: $("#phone").val()
					}, function(resp) {
						// 处理响应的数据
					}, "json");
				});
				
			));
		</script>
	</body>
</html>

$.ajax()

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>easyui提交表单方式1</title>
		<link rel="stylesheet" href="../css/themes/icon.css" />
		<link rel="stylesheet" href="../css/themes/default/easyui.css" />
		<script src="../js/jquery.min.js"></script>
		<script src="../js/jquery.easyui.min.js"></script>
		<script src="../js/easyui-lang-zh_CN.js"></script>
	</head>
	
	<body>
		<form id="ajax_form">
			姓名:<input id="name" />
			年龄:<input id="age" />
			手机号:<input id="phone" />
			
			<button type="button" id="submit"></button>
		</form>
		
		<script>
			$(function(	
				$("#submit").on("click", function() {
					$.ajax({
						url: "/xxx/save",
						type: "post",
						data: {
							name: $("#name").val(),
							age: $("#age").val(),
							phone: $("#phone").val()
						},
						async: true,
						cache: false,
						dataType: "json",
						processData: true,
						success: function(resp) {
							// 处理成功的响应
						},
						error: function(resp) {
							// 处理失败的响应
						}
					});
				});
				
			));
		</script>
	</body>
</html>

第二种:使用easyui提供的表单提交方式

easyui官网已经介绍了这种方式,不过和上面的ajax提交不一样,这种提交方式要给输入框设置name属性。

例如:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>easyui提交表单方式1</title>
		<link rel="stylesheet" href="../css/themes/icon.css" />
		<link rel="stylesheet" href="../css/themes/default/easyui.css" />
		<script src="../js/jquery.min.js"></script>
		<script src="../js/jquery.easyui.min.js"></script>
		<script src="../js/easyui-lang-zh_CN.js"></script>
	</head>
	
	<body>
		<form id="ajax_form">
			姓名:<input id="name" name="name" />
			年龄:<input id="age" name="age" />
			手机号:<input id="phone" name="phone" />
			
			<button type="button" id="submit"></button>
		</form>
		
		<script>
			$(function(
				$("#ajax_form").form("submit", {
					url: "/xxx/save",
					success: function(resp) {
						// 处理成功的响应
					}
				});
				
			));
		</script>
	</body>
</html>

好了,文章就分享到这里了,看完不要忘了点赞+收藏哦~


http://www.kler.cn/news/161569.html

相关文章:

  • Vue练习 v-model 指令在状态和表单输入之间创建双向绑定
  • Vue3集成ThreeJS实现3D效果,threejs+Vite+Vue3+TypeScript 实战课程【一篇文章精通系列】
  • stm32f103使用hal库函数读写内部flash
  • 【分布式微服务专题】从单体到分布式(二、SpringCloud整合Nacos)
  • TR转发路由器测评—云企业网实现跨地域跨VPC的网络互通测评实战【阿里云产品测评】
  • tomcat环境搭建
  • 深入理解Dubbo-1.初识Dubbo
  • Csharp(C#)无标题栏窗体拖动代码
  • 推荐5款很牛的Paas平台编译构建工具
  • .netcore 操作aspose.words导出pdf
  • selenium 执行js后拿不到返回值的原因
  • IT基础监控方案:5台服务器和20台网络设备监控
  • UnityShader自定义cginc文件
  • Intellij idea 快速定位到文件的开头或者结尾的几种方式
  • 预测:2024年的安防监控行业将迎来怎样的变化?
  • 使用postman请求x5接口
  • C语言指针详解上
  • 【推荐系统】了解推荐系统的生态(重点:推荐算法的主要分类)
  • 【Java基础篇 | 面向对象】—— 聊聊什么是接口(上篇)
  • 智能优化算法应用:基于鹰栖息算法无线传感器网络(WSN)覆盖优化 - 附代码
  • 2.HTML进阶
  • 为什么伦敦银交易中支撑和阻力位这么重要?
  • 展开说说:Android之广播接收者
  • 连接服务器的ssh终端自动断开解放方法
  • Comparator Comparators Comparable Collections排序源码解析
  • SRC挖掘漏洞XSS
  • uni-app实现返回刷新上一页
  • 基于selenium工具刷b站播放量(请谨慎使用)
  • Spring AOP从入门到精通
  • <蓝桥杯软件赛>零基础备赛20周--第9周--前缀和与差分