jQuery Form 页面表单提交

<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
<script type="text/javascript">
	//创建测试实例
	function createInstance() {
		var options = {
			success : function(json) {
				if (json.succ) {
					alert(json.info);
					window.parent.ymPrompt.doHandler("close", true);
				}
			}
		};
		$("#f1").ajaxSubmit(options);
	}

	//关闭按钮
	function closeWindow() {
		window.parent.ymPrompt.doHandler("close", true);
	}
</script>


Form表单:

<form id="f1" name="f1" action="${ctx}/process/createInstance.do"
			method="post">
			<table style="width:100%; height:100%">
				<tr>
					<td nowrap="nowrap" style="text-align:right;">测试名称:</td>
					<td><input type="text" name="name" value="${instance.name}"
						style="width:265px;" /><em class="em_user_manage">*</em>
					</td>
				</tr>
				<tr>
					<td nowrap="nowrap" style="text-align:right;">测试场景:</td>
					<td><input type="text" name="scene" style="width:265px;"
						value="${instance.scene}" /><em class="em_user_manage">*</em>
					</td>
				</tr>
				<tr>
					<td nowrap="nowrap" style="text-align:right;">测试目标:</td>
					<td><textarea type="text" name="goal" id="goal" cols="32"
							rows="7">${instance.goal}</textarea>
					</td>
				</tr>
				<tr>
					<td nowrap="nowrap" style="text-align:right;">测试说明:</td>
					<td><textarea type="text" name="description" id="description"
							cols="32" rows="7">${instance.description}</textarea>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="hidden"
						name="extProcessDefinitionId"
						value="${instance.extProcessDefinitionId}" /><input type="hidden"
						name="signIn" value="${instance.signIn}" /><input type="hidden"
						name="definitionId" value="${instance.definitionId}" /><input
						type="button" value="确定" οnclick="createInstance();" /><input
						type="button" value="取消" οnclick="closeWindow();" /></td>
				</tr>
			</table>
		</form>


 

要实现jqueryform表单提交下载文件,可以采用以下步骤: 1. 在前端页面中添加一个表单,用于提交下载文件的请求。 2. 使用jqueryform插件将表单序列化并发送到后台。 3. 后台接收到请求后,根据表单中的参数生成需要下载的文件,并将文件保存到服务器端。 4. 后台将生成的文件路径返回给前端。 5. 前端使用window.open()方法打开返回的文件路径即可实现文件下载。 以下是示例代码: 前端代码: ``` <form id="downloadForm" action="/downloadFile" method="post"> <input type="hidden" name="fileName" value="example.txt"> <input type="hidden" name="fileContent" value="This is an example file."> <input type="submit" value="Download"> </form> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js"></script> <script> $(document).ready(function(){ $("#downloadForm").submit(function(e){ e.preventDefault(); $(this).ajaxSubmit({ success: function(data){ window.open(data); } }); }); }); </script> ``` 后台代码: ``` @RequestMapping(value = "/downloadFile", method = RequestMethod.POST) @ResponseBody public String downloadFile(@RequestParam("fileName") String fileName, @RequestParam("fileContent") String fileContent, HttpServletRequest request, HttpServletResponse response) throws Exception { // 生成文件并保存到服务器端 String filePath = "/path/to/file/" + fileName; File file = new File(filePath); FileWriter writer = new FileWriter(file); writer.write(fileContent); writer.flush(); writer.close(); // 返回文件路径 return filePath; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值