- form表单提交时需要从一个页面跳转至不同的页面,使用js动态提交
例如:1.jsp跳转至2.jsp和3.jsp
<html> |
<form class="form-horizontal" action="xxx" method="post" enctype="multipart/form-data" data- toggle="validator" role="form" novalidate="true" id="patentEditForm"> <button class="btn btn-primary" type="button" id="but_sub">保存</button> <button class="btn btn-primary" type="button">保存返回列表</button> <button class="btn btn-warning" type="button" οnclick="window.location='/biz/project/list';"> 返回 </button> </form> |
$(document).ready(function(){ var buttonId; $('#patentEditForm').validator().on('submit', function (e) { if(buttonId == "but_sub"){ var formData = new FormData($("#patentEditForm")[0]); $.ajax({ type:"POST", url:"/biz/", data: formData, dataType:"JSON", nsync:false, cache: false, contentType: false, processData: false, success:function(date){ switch(date.status){ case 1: $success("保存成功!"); break; case 1009: $error("保存失败!"); break; default : $error("没有提交信息"); } }, error:function(){ $error("没有提交信息"); } }); } }); $(".btn-primary").click(function(){ buttonId = $(this).attr("id"); $('#patentEditForm').trigger('submit'); }); |