form表单提交方式

1.无刷新页面提交表单

表单可实现无刷新页面提交,无需页面跳转,如下,通过一个隐藏的iframe实现,form表单的target设置为iframe的name名称,
form提交目标位当前页面iframe则不会刷新页面

<form action="/url.do" method="post" target="targetIfr">
<input type="text" name="name"/>
</form>
<iframe name="targetIfr" style="display:none"></iframe>

2.通过type=submit提交

一般表单提交通过type=submit实现,input type="submit",浏览器显示为button按钮,通过点击这个按钮提交表单数据跳转到/url.do

<form action="/url.do" method="post">
<input type="text" name="name"/>
<input type="submit" value="提交">
</form>

3.js提交form表单

js事件触发表单提交,通过button、链接等触发事件,js调用submit()方法提交表单数据,jquery通过submit()方法

<form id="form" action="/url.do" method="post">
<input type="text" name="name"/>
</form>

js: document.getElementById("form").submit();
jquery: $("#form").submit();

4.ajax异步提交表单数据

采用ajax异步方式,通过js获取form中所有input、select等组件的值,将这些值组成Json格式,通过异步的方式与服务器端进行交互,
一般将表单数据传送给服务器端,服务器端处理数据并返回结果信息等

<form id="form"  method="post">
<input type="text" name="name" id="name"/>
</form>
var params = {"name", $("#name").val()}
$.ajax({
type: "POST",
url: "/url.do",
data: params,
dataType : "json",
success: function(respMsg){
}
});

5.页面无跳转

如果通过form表单提交请求服务端去下载文件,这时当前页面不会发生跳转,服务端返回void,通过response 去写文件数据,
页面会显示下载文件。

<form action="/url.do" method="post">
<input type="text" name="name"/>
<input type="submit" value="提交">
</form> @RequestMapping(value = "/url")
public void exportFile(HttpServletRequest req, HttpServletResponse response, String rptId)
throws Exception {
OutputStream out = null;
try {
String rptName = "file";
String fileName = new String((rptName + excelAble.getFileSuffix()).getBytes("GBK"),
"8859_1");
response.reset();
response.setContentType("application/octec-stream");
response.setHeader("Content-disposition", "attachment; filename=" + fileName);
out = response.getOutputStream();
excelAble.exportFile(out);
} catch (Exception e) {
logger.error(e);
} finally {
if (out != null) {
out.close();
}
}
}

6.form表单上传文件

使用form表单进行上传文件需要为form添加enctype="multipart/form-data" 属性,除此之外还需要将表单的提交方法改成post,
如下 method="post", input type的类型需要设置为file

 <form action="/url.do" enctype="multipart/form-data" method="post">
<input type="file" name="name"/>
<input type="submit" value="提交">
</form>

24.form表单提交的六种方式的更多相关文章

  1. form表单提交信息的方式

    form表单提交信息的方法有两种,一种是get,一种是post.get提交的数据是在地址栏上提交,一般隐私数据不会选择这样方式.地址栏上只能提交字符. 如果使用的是post提交,那么信息都在消息正文中 ...

  2. form表单提交转为ajax方式提交

    <form action="xxx" method="get"> //action的值是请求的url地址 <div class="f ...

  3. form表单提交三种方式,demo实例详解

    第一种:使用type=submit  可以直接提交 <html> <head> <title>submit直接提交</title> </head& ...

  4. Form表单提交的简要方式

    <html> <head> <meta name="viewport" content="width=device-width" ...

  5. Form表单提交数据的几种方式

    一.submit提交 在form标签中添加Action(提交的地址)和method(post),且有一个submit按钮(<input type='submit'>)就可以进行数据的提交, ...

  6. Checkbox框全选操作,form表单提交与jquery ajax提交两种处理方式

    //1.jquery ajax<script type="text/javascript"> $(function(){ var basePath = $(" ...

  7. Form 表单提交的几种方式

    简单的总结一下form表单提交的几种方式:1.最简单的方式 就用form的submit提交方式,这种提交方式是不需要回调函数的   这种方式最近到一个form提供action路径后台接受就可以< ...

  8. form表单提交方式

    form表单提交方式总结一下: 一.利用submit按钮实现提交,当点击submit按钮时,触发onclick事件,由JavaScript里函数判断输入内容是否为空,如果为空,返回false, 不提交 ...

  9. form表单提交,后台怎么获取select的值?后台直接获取即可,和input方式一样。

    form表单提交,后台怎么获取select的值? 后台直接获取即可,和后台获取input的值方式一样. form提交后,后台直接根据select的name获取即可,即getPara("XXX ...

随机推荐

  1. [No0000100]正则表达式匹配解析过程分析(正则表达式匹配原理)&regexbuddy使用&正则优化

    常见正则表达式引擎引擎决定了正则表达式匹配方法及内部搜索过程,了解它至关重要的.目前主要流行引擎有:DFA,NFA两种引擎. 引擎 区别点 DFA Deterministic finite autom ...

  2. 为什么实数系里不存在最小正数?(Why the smallest positive real number doesn't exist in the real number system ?)

    We define the smallest positive real number as the number which is explicitly greater than zero and ...

  3. 部署Java项目到阿里云服务器主机

    https://m.aliyun.com/jiaocheng/548684.html https://blog.csdn.net/qq_30865575/article/details/7827329 ...

  4. window.location.reload(false);window.location.reload(true);history.Go(0)区别

    在日常工作中常用的页面刷新方式的区别: 1 window.location.reload(false);  先说说window.location.reload(false);当我们window.loc ...

  5. 创建本地SVN版本库以及将SVN导入GIT

    创建本地SVN 通常SVN作为一种服务,是在服务器上架设,供用户通过网络访问使用.但如果只是自己日常使用,完全可以架设在本机上,不需要启动后台程序,通过文件的方式访问即可. 建立本地SVN非常简单,一 ...

  6. arcgis10.4 server第一次发布地图报错:We were unable to connect to...Error:Proxy server got bad address...

    arcgis 10.4发布地图跟10.2不一样.server url里的http要改为https,否则就会连接不上.

  7. TableView刷新跳动问题

    https://juejin.im/post/5aca1a04f265da2391486533 解决办法: 将估算高度设置为0即可: tableView.estimatedRowHeight = 0; ...

  8. [报错]ios开发 failed to read file attributes for

    下载第三方demo,运行报错:   failed to read file attributes for https://stackoverflow.com/questions/46301270/fa ...

  9. 将DOS格式的shell脚本转为UNIX格式

    shell脚本是UNIX格式,在修改其中内容时,务必保持UNIX格式.UE编辑器打开时,会询问是否转为DOS格式,请点否.如果修改完成后,不能确认是否为DOS格式,可以使用UE文件菜单下的Conver ...

  10. Oracle shrink table

    shrink必须开启行迁移功能. alter table table_name enable row movement ; 在oracle中可以使用alter table table_name shr ...