Ajax提交表单初接触
<!doctype html> <html class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>签到test</title> <!-- Set render engine for 360 browser --> <meta name="renderer" content="webkit"> <!-- No Baidu Siteapp--> <meta http-equiv="Cache-Control" content="no-siteapp"/> <!-- Add to homescreen for Chrome on Android --> <meta name="mobile-web-app-capable" content="yes"> <!-- Add to homescreen for Safari on iOS --> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-title" content="Amaze UI"/> <meta name="msapplication-TileColor" content="#0e90d2"> <!-- SEO: If your mobile URL is different from the desktop URL, add a canonical link to the desktop page https://developers.google.com/webmasters/smartphone-sites/feature-phones --> <!-- <link rel="canonical" href="http://www.example.com/"> --> <link rel="stylesheet" href="assets/css/amazeui.min.css"> <link rel="stylesheet" href="assets/css/style.css"> </head> <body> <!--[if lte IE 9]> <p class="browsehappy">你正在使用<strong>过时</strong>的浏览器,Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a> 以获得更好的体验!</p> <![endif]--> <!-- 开始写代码 --> <!-- banner --> <div data-am-widget="slider" class="am-slider am-slider-a1" data-am-slider='{"directionNav":false}' > <ul class="am-slides"> <li> <img src="assets/img/banner1.png"> </li> <li> <img src="assets/img/banner1.png"> </li> </ul> </div> <form class="form_box" id="form" action="/users/login"> <div class="form_group"> <div class="group_box"> <span class="am-fl"><i class="icon iconfont"></i></span> <input type="text" placeholder="姓名" name="name"> </div> </div> <div class="form_group"> <div class="group_box"> <span class="am-fl"><i class="icon iconfont"></i></span> <input type="text" name="phone" placeholder="电话"> </div> </div> <div class="am-form-group"> <div class="am-u-sm-12 tc"> <button type="button" class="am-btn am-btn-default" onclick="login()">登录</button> </div> </div> </form> <!-- 代码结束 --> <!--[if lt IE 9]> <script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script> <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script> <script src="assets/js/amazeui.ie8polyfill.min.js"></script> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <!--<![endif]--> <script src="assets/js/amazeui.min.js"></script> <script src="assets/js/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#form').validate({ rules:{ user:{ required:true, minlength:2, }, phone:{ required:true, minlength:11, }, }, messages:{ user:{ required:'账号不得为空', minlength:'账号不得小于2位', isMobile : true }, phone:{ required : "请输入手机号", minlength : "不能小于11个字符", isMobile : "请正确填写手机号码" }, }, }); }) var name='夏小夏'+'18211013898';//用参数拼接的方法 //ajax提交表单 function login() { $.ajax({ //几个参数需要注意一下 type: "POST",//方法类型 dataType: "json",//预期服务器返回的数据类型 url: "" ,//url data: {mid:'4900310296747830231',name:name,password:'123456'},//$('#form').serialize(), success: function (result) { console.log(result);//打印服务端返回的数据(调试用) if (result.resultCode == 200) { alert("SUCCESS"); } }, error : function() { alert("异常!"); } }); } </script> </body> </html>
要注意的问题:
1、如果是form提交的话,可以用submit;如果是ajax提交表单用type=button,这样更方便;
2、//$('#form').serialize(),//序列化表单—— 注释的这句不建议使用,不够灵活,因为在ajax需要灵活的提交所需要的参数
Ajax提交表单初接触的更多相关文章
- Jquery ajax提交表单几种方法
在jquery中ajax提交表单有post与get方式,在使用get方式时我们可以直接使用ajax 序列化表单$('#表单ID').serialize();就行了,下面我来介绍两个提交表单数据的方法. ...
- Validator验证Ajax提交表单的方法
Validator验证Ajax提交表单的方法 转自:http://hunanpengdake.iteye.com/blog/1671360 当我们在一些稍微复杂的业务时,可能会遇到需要多个表单form ...
- lavarel框架中如何使用ajax提交表单
开门见山,因为laravel以post形式提交数据时候需要加{{csrf_field()}}防止跨站攻击,所以当你用ajax提交表单时候自然也要加 在网上看了很多的解决方式,我是用下面这种方法解决的: ...
- Jquery ajax提交表单几种方法详解
[导读] 在jquery中ajax提交表单有post与get方式,在使用get方式时我们可以直接使用ajax 序列化表单$( 表单ID) serialize();就行了,下面我来介绍两个提交表单数据的 ...
- ajax提交表单序列化(serialize())数据
知识点: $("#form").serialize();将表单数据序列化为标准URL编码文本字符串(key1=value1&key2=value2…). 以下用一个例子来演 ...
- jquery实现ajax提交表单
一般情况下,我们提交form表单采用的是submit的方法,典型的场景如下. <form id="thisForm" method="post" acti ...
- ajax提交表单、ajax实现文件上传
ajax提交表单.ajax实现文件上传,有需要的朋友可以参考下. 方式一:利用from表单的targer属性 + 隐藏的iframe 达到类似效果, 支持提交含有文件和普通数据的复杂表单 方式二:使用 ...
- KindEditor:Ajax提交表单时获取不到HTML内容
当用Ajax提交表单时,KindEditor的内容获取不到,HTML数据获取不了 原因:当ajax提交时,KindEdito的HTML数据还没有同步到表单中来,那怎么去获取HTML数据呢? ----- ...
- php使用jquery Form ajax 提交表单,并上传文件
在html5中我们通过FormData就可以ajax上传文件数据,不过因为兼容问题.我们选用jquery.form.min.js来进行ajax的表单提交. 一.jquery.form.js下载地址 ...
随机推荐
- 如何解决angular不自动生成spec.ts文件
"schematics":{ "@schematics/angular:component": { "styleext": ...
- openlayers3 实现点选的几种方式
WebGIS开发中,点击查询是最常用的一种查询方式,在ArcGIS api 中,这种查询叫IdentifyTask,主要作用是前台提交参数,交ArcServer查询分析返回.本文从开源框架的角度,从前 ...
- java 线程方法 ---- yiled()
class MyThread3 implements Runnable{ @Override public void run() { for (int i = 0; i < 3; i++){ / ...
- 监控工具之zabbix server3.4 部署配置
[root@localhost src]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@localhost s ...
- 仿9GAG制作过程(三)
有话要说: 这次准备讲述后台服务器的搭建以及前台访问到数据的过程. 成果: 准备: 安装了eclipse 安装了Tomcat7 安装了数据库管理工具:Navicat 搭建服务器: 用eclipse直接 ...
- 微信小程序(一),授权页面搭建
wxml代码如下: <!--pages/index2/index2.wxml--> <view class="index2Container"> <i ...
- C/C++ -- 插入排序算法
索引: 目录索引 参看代码 GitHub: Sort.cpp 代码简要分析说明: 1.for(int i=1;i<nSize;i++) 这个外层的for循环, [0][1],[1][2],[2] ...
- SQL Server GUID 数据迁移至MongoDB后怎样查看?
关键字:SQL Server NEWID():BSON:MongoDB UUID 1.遇到的问题和困惑 SQL Server中的NEWID数据存储到MongoDB中会是什么样子呢?发现不能简单的通过此 ...
- 安装vmware-tools遇the path "" is not valid path to the gcc binary和the path "" is not a valid path to the 3.10.0-327.e17.x86_64 kernel headers问题解决
#./vmware-install.pl踩点: 1.the path "" is not valid path to the gcc binary 2.the path " ...
- C# 第十版
地址: https://files.cnblogs.com/files/blogs2014/%E9%AB%98%E7%BA%A7%E7%BC%96%E7%A8%8B%28%E7%AC%AC11%E7% ...