这是我用来显示登录弹出窗口的代码。单击登录按钮时无效。我重新加载或刷新页面后登录工作。 任何人都可以帮助我如何解决这个问题? 非常感谢。
查看代码:
<form id="loginForm" class="myform" method="POST" novalidate="novalidate">
<div class="form-group focus">
<label for="username" class="control-label">Email ID</label>
@Html.TextBoxFor(m => m.EmailID, new {autofocus = "autofocus",@class = "form-control", placeholder = "Please enter the valid email" })
@Html.ValidationMessageFor(m => m.EmailID, null, new { @class = "validmsg" })
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="password" class="control-label">Password</label>
@Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Please enter password" })
@Html.ValidationMessageFor(m => m.Password, null, new { @class = "validmsg" })
<span class="help-block"></span>
</div>
<div id="loginErrorMsg" class="alert alert-error hide">Wrong username or password</div>
<div class="checkbox">
<label style="float:left;">
<input type="checkbox" name="remember" id="remember"> Remember login
</label>
<p class="help-block forinfo"><i class="fa fa-info-circle fa-lg"></i> if this is a private computer</p>
</div>
<button type="submit" id="LoginFormSubmit" class="btn-success btn-block">Login</button>
</form>
脚本代码:
$('#LoginFormSubmit1').click(function (e) {
if ($("#loginForm1").valid()) {
$.post('/Account/Login', $('#loginForm1').serialize(), function (data, status, xhr) {
if (data.Status == 0) {
debugger
$.ajax({
type: "GET",
url: "/Home/index",
contentType: "application/json;charset=utf-8",
data: { "City": localStorage.getItem('popState') },
success: function (response) {
debugger
var IS_JSON = true;
try {
var result = $.parseJSON(response);
}
catch (err) {
IS_JSON = false;
}
if (!IS_JSON) {
$("#myList").html('');
$("#myList").html(response);
}
},
error: function (result) {
}
});
}
else {
debugger
$('#alertbox').show();
$('#Statsmessage').text(data.StatusDesc);
setTimeout(function () {
$("#myModal").hide();
}, 2000);
}
})
}
else {
return false;
}
e.preventDefault();
});