html from表单异步处理
from表单异步处理. 简单处理方法: jQuery做异步提交表单处理, 通过$("#form").serialize()将表单元素的数据转化为字符串, 最后通过$.ajax()执行异步请求资源.
demo示例:
html 文件
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>信息登记表异步提交</title>
<style type="text/css">
.grayBox{
backGround-color:#e0e0e0;
}
table{
text-align:center;
}
</style>
</head> <body>
<form onsubmit="return false" id="formAsync">
<table border="1" rules="all" bordercolor="#000000" >
<tr>
<th colspan="2" height="50">信息登记表</th>
</tr>
<tr class="grayBox" height="70">
<td width="50" >姓名</td>
<td><input type="text" name="username" size="16"/></td>
</tr>
<tr height="70">
<td>性别</td>
<td>
<input type="radio" name="sex" value="boy" checked="checked"/>男
<input type="radio" name="sex" value="girl"/>女
</td>
</tr>
<td colspan="2" height="40">
<input type="submit" value="提交信息" onclick="requestAsync()"/>
<input type="reset" value="重置"/>
</td>
</tr>
</table>
</form>
</body> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function requestAsync() {
$.ajax({
type: "POST",
dataType: "json",
url: "test.php",
data: $('#formAsync').serialize(),
success: function (data) {
console.log(data);
if(data.code ==200){
var username = data.msg +' 姓名:'+data.username
alert(username);
}else{
alert(data.msg);
}
},
error : function() {
alert("操作异常!");
}
});
}
</script>
</html>
test.php 文件
<?php
$username = !empty($_POST['username']) ? trim($_POST['username']) :'';
$sex = $_POST['sex']; //简单逻辑判断
if($username){
msg(200,'异步处理成功.',$username,$sex);
}else{
msg(400,'数据处理失败,请输入姓名!');
} function msg($code,$msg,$username='',$sex=''){
exit(json_encode([
'code'=> $code,
'msg' => $msg,
'username' => $username,
'sex' => $sex
]));
}
结果打印:

html from表单异步处理的更多相关文章
- 使用jQuery.form插件,实现完美的表单异步提交
传送门:异步编程系列目录…… 时间真快,转眼一个月快结束了,一个月没写博客了!手开始生了,怎么开始呢…… 示例下载:使用jQuery.form插件,实现完美的表单异步提交.rar 月份的尾巴,今天的主 ...
- 使用jQuery,实现完美的表单异步提交
jQuery异步提交表单 <form id="form1" method="post"> <table border="1" ...
- yii2 modal弹窗之ActiveForm ajax表单异步验证
作者:白狼 出处:http://www.manks.top/yii2_modal_activeform_ajax.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位 ...
- .net mvc中的表单异步提交
// // 摘要: // 将 <form> 开始标记写入响应. // // 参数: // ajaxHelper: // AJAX 帮助器. // // actionName: // 将处理 ...
- Ajax表单异步上传(包括文件域)
起因 做前台页面时,需要调用WebAPI的Post请求,发送一些字段和文件(相当于把表单通过ajax异步发送出去,得到返回结果),然后得到返回值判断是否成功. 尝试 先是尝试了一下 "jQu ...
- jquery.form.js 使用以及问题(表单异步提交)
标注:我引用的js后报错 原因:是引用的js有冲突 我引用了两便jQuery: 转载:https://blog.csdn.net/cplvfx/article/details/80455485 使用方 ...
- jQuery——表单异步提交
如果不做任何处理,表单提交时会刷新页面,为了改善体验,可以使用jQuery做到异步提交表单:通过$("#form").serialize()将表单元素的数据转化为字符串,然后通过$ ...
- vue中的表单异步校验方法封装
在vue项目的开发中,表单的验证必不可少,在开发的过程中,用的是vue+iview的一套,我们知道iview的表单验证是基于async-validator,对于async-validator不熟悉的可 ...
- jquery让form表单异步提交
1.监听表单提交事件,并阻止表单提交 $("form").submit(function(e) { return false;//阻止表单提交 }) 2.拿到表单内容 let da ...
随机推荐
- st.getParameter() 和request.getAttribute() 区别 https://terryjs.iteye.com/blog/1317610
getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute. (1)request.getParameter() 取得是通过容 ...
- Java ——方法
本节重点思维导图 方法的定义 例题:1!+2!+3!+4!+…..+15!=? public class Demo { public static void main(String[] args) ...
- 20191003 尚硅谷Spring Cloud教学视频
视频信息 视频日期:2018-4-19 讲师:尚硅谷周阳 Spring Cloud版本:Dalston.RELEASE 当前版本:Greenwich SR3 微服务.微服务架构.Spring Clou ...
- gitlab上传代码及报错总结
将目录变成git可管理的仓库 git init 将文件添加到暂存区中 git add README.md 将文件提交到仓库 git commit -m "fisrt commit" ...
- Java-Lambda表达式第一篇认识Lambda表达式
1.Lambda表达式时Java 8新增的特性.Lambda表达式支持将代码块作为方法参数,Lambda表达式允许使用更简洁的代码创建只有一个抽象方法的接口(即函数式接口)的实例. 2.当使用Lamb ...
- 数论(lcm)
CodeForces - 1154G You are given an array a consisting of n integers a1,a2,…,an . Your problem is to ...
- selenium安装及环境搭建
说明:安装selenium前提必须是安装好了python和pip 1.安装python 在Python的官网 www.python.org 中找到最新版本的Python安装包(我的电脑是windows ...
- Python的__pycache__的文件夹
· 前言 用python编写好一个工程,在第一次运行后,总会发现工程根目录下生成了一个__pycache__文件夹,里面是和py文件同名的各种 *.pyc 或者 *.pyo 文件. 先大概了解一下py ...
- 数据挖掘 workfolw 总结
个人将数据挖掘的流程简单表示为“ 数据 → 特征 → 模型 ”. 首先,明确问题的性质和任务(分类.回归.聚类.推荐.排序.关联分析.异常检测等): 其次,理解数据(含义.类型.值的范围),并通过 ...
- Topcoder SRM656div1 250 ( 期望DP )
Problem Statement Charlie has N pancakes. He wants to serve some of them for breakfast. We will n ...