jquery提交form及实现ajax刷新

<script type="text/javascript" src="${pageContext.request.contextPath}/style/js/jquery.form.js"></script>
<form action="${pageContext.request.contextPath}/pcSystemSetting/changeInformation" 
      id="form_myinformation"name="myonformationform" method="post" enctype="multipart/form-data"> 
	<div title="基本资料">
		<table border=0>
			<tr>
				<td align="right">账号</td>
				<td><input type=text id="account" name="account" value="${wxUser.wxUserName}" readonly/></td>
				<td align="right">姓名(公司简称)</td>
				<td><input type=text id="comName" name="name" value="${wxUser.wxUserRealname}" /></td>
				<td align="right">身份证号</td>
				<td><input type=text id="idcard" name="idcard"value="${wxUser.wxIdNumber}" /></td>
			</tr>
			<tr>
				<td align="right">手机</td>
				<td><input type=text id="phone" name="phone"value="${wxUser.wxUserContact1}" /></td>
				<td align="right">电话</td>
				<td><input type=text id="tel" name="tel" value="${wxUser.wxUserContact2}" /></td>
				<td align="right">角色权限</td>
				<td>
					<select name="jsqx" id="jsqx" style="width: 155px; height: 22px;" onclick="getrolename()">
					<option value="0">--请选择--</option>
					<c:forEach items="${roleList}" var="ROL" varStatus="idxStatus">
					<option value="${ROL.idwxRole}"
					<c:forEach items="${getUserRole}" var="WXR" varStatus="idxStatus">
					<c:if test="${idxStatus.index==0}">
					<c:if test="${role_name=='技师' && ROL.idwxRole==2}">  selected  </c:if>
					<c:if test="${role_name!='技师' }">
					<c:if test="${WXR.idwxRole==ROL.idwxRole}">selected</c:if>
					</c:if>
					</c:if>
					</c:forEach>>${ROL.wxRoleName}</option>
					</c:forEach>
					</select>
					<input type="hidden" id="jsqu_roleId" name="roleId" value="" />
					<input type="hidden" id="getroleName" name="roleTypeName" value="${role_name}"/>
				</td>
			</tr>
			<tr>
				<td align="right">QQ</td>
				<td><input type=text id="qq" name="qq" value="${wxUser.wxUserQQ}" /></td>
				<td align="right">支付宝账号</td>
				<td><input type=text id="alipay" name="alipay" value="${wxUser.wxQianbao.wxQianbaoZhifubao}" /></td>
				<td align="right">邮箱</td>
				<td><input type=text id="email" name="email" value="${wxUser.wxUserEmail}" /></td>
			</tr>
			<tr>
				<td align="right">地址</td>
				<td colspan="6">
					<c:choose>
						<c:when test="${empty  addressList}">
							<input type=text id="pro" name="pro" style="width:100px;"/>&nbsp;省 
							<input type=text id="city" name="city" style="width:100px;"/>&nbsp;市 
							<input type="text" id="dis" name="dis"  style="width:105px;"/>&nbsp;区 
							<input type=text id="det" name="det" style="width:300px;"/>&nbsp;街道
						</c:when>
						<c:otherwise>
							<c:forEach items="${addressList}" var="addr">
								<input type=text id="pro" name="pro"
								value="${addr.wxAddressProvince}"  style="width:100px;"/>&nbsp;省 
								<input type=text id="city" name="city"
								value="${addr.wxAddressCity}" style="width:100px;"/>&nbsp;市 
								<input type="text" id="dis" name="dis"
								value="${addr.wxAddressDistrict}" style="width:105px;"/>&nbsp;区 
								<input type=text id="det" name="det"
								value="${addr.wxAddressDetailed}" style="width:300px;"/>&nbsp;街道
							</c:forEach>
						</c:otherwise>
					</c:choose>
			       </td>
			</tr>
			<tr>
				<td align="right">状态设置</td>
				<td colspan="5">
					<input type="radio" name="userType"
					      <c:if test="${wxUser.wxUserUserType == 0}">checked="checked" </c:if>
					value="0" />新建账户 
					<input type="radio" name="userType"
					      <c:if test="${wxUser.wxUserUserType == 1}">checked="checked" </c:if>
						    value="1" />在线使用
					<input type="radio" name="userType"
					      <c:if test="${wxUser.wxUserUserType == 2}">checked="checked" </c:if>
					value="2" />停用账户
				</td>
			</tr>
			<tr>
				<td colspan="6" align="center">
					<input type=file name="myfile" id="myfile" />
					<img src="${wxUser.uploadImg}" id="img_user_file" style="height: 180px; width: 190;" />
				</td>
			</tr>
			<tr>
				<td align="center" colspan="6">
					<input type="hidden" name="butType" id="butType" value="确认修改" />
					<input type="button" value="确认修改" onclick="changeAccountInfo()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="button" value="账号激活" onclick="activate()" />
				</td>
			</tr>
		</table>
	</div>
</form>
function changeAccountInfo() {
				$("#butType").val("确认修改");
				var RolePermissions = $("#jsqx").val(); //角色权限id
				if (RolePermissions == 0) {
					$.messager.alert('提醒','请选择角色','error');
					return;
				}
				
				$("#jsqu_roleId").val(RolePermissions);
				$("#form_myinformation").submit(function(){
					var options = {
							error: changeAccount_error,
							success: changeAccount_success
					};
					$(this).ajaxSubmit(options);
					return false;
				});
				$("#form_myinformation").submit();
			}
			
			function changeAccount_success(data, status) {
				data = eval("("+ data + ")");
				if (data.result == "1") {
					alert("修改成功!");
				} else if (data.result == "0") {
					alert("修改失败!");
				} else {
					alert(data.message);
				}
				
				if (data.imgfile != undefined && data.imgfile != "") {
					$("#img_user_file").attr("src", data.imgfile);
				}
			}
			
			function changeAccount_error(data) {
				alert(data);
			}

猜你喜欢

转载自1160514291.iteye.com/blog/2211092