待提交的表单
<form id="updatePublicKey" enctype="multipart/form-data">
<div class="left">
<ul>
<li>
<div class="label">邮箱</div>
<div class="ui corner labeled disabled input">
<input type="text" disabled="disabled" value="${user.email}" placeholder="Required Field" />
</div>
</li>
<li>
<div class="label">用户名</div>
<div class="ui corner labeled disabled input">
<input type="text" disabled="disabled" value="${user.username}" placeholder="Required Field" />
</div>
</li>
<li>
<div class="label">
<span>*</span>Sudo密码</div>
<div class="ui corner labeled input">
<input type="password" iplaceholder="" id="password" name="password" />
</div>
<p class="italic inputdescription">需包含字母、数字、符号,八位及以上。
<br />Sudo密码在设备上切换到管理员用户时将使用。</p>
<p class="red" id="sudoNo" style="display: none;">密码不符合规则</p>
</li>
<li>
<div class="label">
<span>*</span>Sudo密码确认</div>
<div class="ui corner labeled input">
<input type="password" placeholder="" id="passwordconfirm" name="passwordconfirm" />
</div>
<p class="red" id="twiceNo" style="display: none;">两次密码输入不一致</p>
</li>
</ul>
</div>
<input id="submit" type="button" class="ui teal button uploadsubmit" value="提交" style="border:0;"/>
</form>
ajax提交Form表单
$("#submit").click(function(){
var $form = $("#updatePublicKey");
var formData = new FormData($form[0]);
formData.append("userName", userName);//添加参数数据
$.ajax({
url: updatekey_url,
data:formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
xhr: function() {
myXhr = $.ajaxSettings.xhr();
return myXhr;
},
success: function(json) {
//
if (json.status == 0) {
location.href = publickey_index_url;
} else {
alert(json.msg);
}
}
});
});