我在模態彈出視窗中有一個表單?
<form asp-controller="Account" asp-action="Register">
<div id="Register-Form" hidden>
<div >
<input type="password" name="user_Password" maxlength="6" id="Register-NewPassword">
</div>
<div >
<input type="number" maxlength="6" autocomplete="off" id="Register-ActiveCode">
</div>
<div >
<button type="submit" onclick="return Validate_Register()" >Save </button>
</div>
</div>
Jquery 驗證:
function Validate_Register() {
$.post("/Account/CheckActiveCode", {
Mobile: Login_Mobile, ActiveCode: Register_Active_Value
}, function (data) {
if (data == 1) {
$.alert({
title: 'Error',
content: 'Active Code is Not True',
rtl: true,
closeIcon: true,
type: 'red',
typeAnimated: true,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-red',
}
},
});
return false;
}
});
return true;
}
控制器 :
public JsonResult CheckActiveCode(string Mobile , string ActiveCode)
{
if (!_user.UserIsActivate(Mobile, ActiveCode))
{
return Json(1);
}
return Json(0);
}
提交的控制器表單:
[HttpPost]
public IActionResult Register(string mobile_User, string user_Password)
{
_user.RegisterUpdateUser(mobile_User, user_Password);
return RedirectToAction("Index", "Home");
}
如果驗證(data==0)如果(data==1),表單將不會提交并顯示錯誤,我希望表單提交?
uj5u.com熱心網友回復:
嘗試使用<input type="button"/>替換<button></button>,如果data !=1,提交表單。
html代碼:
<form id="myForm" asp-controller="Account" asp-action="Register">
<div id="Register-Form" hidden>
<div >
<input name="mobile_User" maxlength="6" id="mobile_User">
</div>
<div >
<input type="password" name="user_Password" maxlength="6" id="Register-NewPassword">
</div>
<div >
<input type="number" maxlength="6" autocomplete="off" id="Register-ActiveCode">
</div>
<div >
<input type="button" onclick="Validate_Register()" value="Save" />
</div>
</div>
</form>
js:
function Validate_Register() {
$.post("CheckActiveCode", {
Mobile: Login_Mobile, ActiveCode: Register_Active_Value
}, function (data) {
if (data == 1) {
$.alert({
title: 'Error',
content: 'Active Code is Not True',
rtl: true,
closeIcon: true,
type: 'red',
typeAnimated: true,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-red',
}
},
});
} else {
$("#myForm").submit();
}
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/317603.html
上一篇:遷移AppEngine使用GoogleCloudLoadBalancer導致約1小時的停機時間
下一篇:更改特定端點的api路由
