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

前端之家收集整理的这篇文章主要介绍了ajax提交form表单,关键代码:$("#theForm").serialize()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

原始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",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>


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

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

原文链接:https://www.f2er.com/ajax/164527.html

猜你在找的Ajax相关文章