form表单的action提交写到js中来,同时onclick事件也写在js中来。其action也可以通过ajax来提交的。

时间:2021-03-24 12:24:40

1,html脚本

<body>
<div style="display: none;">
<form id="submitForm" action="" method="post"  enctype="multipart/form-data">
<input type="hidden" name="wxOpenId" value="${wxOpenId}"/>
<input type="hidden" name="applyId" value="${applyId}"/>
<input type="hidden" name="wxModuleType" id="wxModuleType" value=""/>
</form>
</div>
<div class="fft-wrapper">
<div class="tab-wrapper">

2,通过js脚本来传递action

$(function(){
$("span.fr").click(function(){
var id = $(this).attr("id");
$("#wxModuleType").val(id);
var url = '${rc.contextPath}/wxFfanApply.htm?method=preSubPage';
document.getElementById('submitForm').action = url;
document.getElementById('submitForm').submit();
});
});

3,另一种方法就是通过ajax来序列化的传递参数,但是这时候不能是enctype="multipart/form-data"这种格式的,如果非得这样传的话见springmvc + ajaxfileupload解决ajax不能异步上传图片的问题

$(function() {
$(".btn-submit").click(function() {
var url = '${rc.contextPath}/wxFfanApply.htm?method=save';
var param = $("#submitForm").serialize();
$.post(url, param, function(data) {
alert("jjjjj");
}, 'json');

}