现在的位置: 首页 > 综合 > 正文

ajax提交form表单,关键代码:$(“#theForm”).serialize()

2017年12月27日 ⁄ 综合 ⁄ 共 1094字 ⁄ 字号 评论关闭

原始ajax提交:

$.ajax({
						type: "POST",
						data:"processId="+$("#processId").val()+"&delstepids="+delstepids,
						url: "./delStepForProcess.jspx",
						dataType: "text",
						cache: false,
						success: function(data){	
							if(1==data){
							alert("删除失败!");
							return;
							}else{
							location.reload(); 
							}
						}
			        });

data:"参数1="+参数值

ajax提交form:

$.ajax({
			type: "POST",
			data:$("#theForm").serialize(),
			url: "${basePath}/public/sjkf/serveyanswer/saveData.jspx",
			dataType: "text",
			cache: false,
			success: function(data){	
				if(1==data){
					alert("删除失败!");
					
				}else{
					
				}
			}
        });

data:$("#form的id").serialize()

action(或者controller)中接受参数:

request.getParameter("token");

返回信息:

PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/json;charset=UTF-8");
			out =response.getWriter();
			customProcessService.modifyStepToStart(processId,stepId);
			out.println("0");
		} catch (Exception e) {
			out.println("1");
			e.printStackTrace();

		}finally{
			if(out!=null){
				out.close();
			}
		}

<form action="" id="theForm" name="theForm" enctype="multipart/form-data" method="post" >

</form>

-----------------------------------------------------------------------------------------------------------------------

不能认怂.....................

抱歉!评论已关闭.