我有一个显示登录模式的模式表单,但每当我试图提交时,即使我没有填写输入,它的不断重新加载页面,我已经尝试复制有效的代码,但它在我的特定页面中仍然有效。如果你知道答案,请帮我知道错误。谢谢
模式:
<div class="modal fade" id="loginClub" tabindex="-1" role="dialog" arialabelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Login User SSB/CLUB</h4>
</div>
<div class="modal-body">
<center><img src="<?= base_url('files/gambar/logoclub/1577137969.png') ?>" width="100px"></center>
<div class="text-center"><strong>GARUDA ANAK NUSANTARA</strong></div>
<?php echo form_open('',' id="FormulirLogin" ');?>
<div class="form-group mb-lg no_hp">
<label class="control-label">No. HP</label>
<div class="input-group input-group-icon">
<input name="no_hp" type="text" class="form-control input-lg" placeholder="Masukkan Nomor HP sebagai Username"/>
<span class="input-group-addon">
<span class="icon icon-lg">
<i class="fa fa-user"></i>
</span>
</span>
</div>
</div>
<div class="form-group mb-lg password">
<label class="control-label">Password</label>
<div class="input-group input-group-icon ">
<input name="password" type="password" class="form-control input-lg" placeholder="Masukkan Password"/>
<span class="input-group-addon">
<span class="icon icon-lg">
<i class="fa fa-lock"></i>
</span>
</span>
</div>
</div>
<button class="btn btn-primary btn-block btn-lg" id="submitform">Login</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<hr>
<div class="text-right">
<strong>Belum terdaftar?</strong> <br /><a href="daftar">Klik di sini untuk mendaftar...</a><br />
<strong>Lupa password?</strong> <br /><a href="lupapass">Klik di sini untuk reset password...</a>
</div>
</div>
</div>
</div>
</div>
按钮显示模式:
<li><a href="javascript:void(0)" data-toggle="modal" data-target="#loginClub">Login Club</a></li>
Ajax:
$("#FormulirLogin").submit(function(e) {
blurForm();
$('.help-block').hide();
$('.form-group').removeClass('has-error');
$("#submitform").attr("disabled", true);
$('#submitform').html('Loading ...');
var form = $('#FormulirLogin')[0];
var formData = new FormData(form);
$.ajax({
type : 'POST',
url : '<?php echo base_url()?>loginclub/authlogin',
data : formData,
processData: false,
contentType: false,
cache: false,
dataType : 'json'
}).done(function(data) {
if ( ! data.success) {
$('input[name=<?php echo $this->security->get_csrf_token_name();?>]').val(data.token);
window.setTimeout(function() {
$("#submitform").attr("disabled", false);
$('#submitform').html('Login');
var objek = Object.keys(data.errors);
for (var key in data.errors) {
if (data.errors.hasOwnProperty(key)) {
var msg = '<div class="help-block" for="'+key+'">'+data.errors[key]+'</span>';
$('.'+key).addClass('has-error');
$('input[name="' + key + '"]').after(msg);
}
}
}, 500);
return false;
} else {
$('input[name=<?php echo $this->security->get_csrf_token_name();?>]').val(data.token);
PNotify.removeAll();
$("#submitform").attr("disabled", false);
$('#FormulirLogin')[0].reset();
$('#submitform').html('Login');
new PNotify({
title: 'Notifikasi',
text: data.message,
type: 'success'
});
window.location='<?php echo base_url()?>'+data.beranda;
}
}).fail(function(data) {
$("#submitform").attr("disabled", false);
$('#submitform').html('Login');
new PNotify({
title: 'Notifikasi',
text: "Request gagal, browser akan direload",
type: 'danger'
});
window.setTimeout(function() { }, 2000);
});
e.preventDefault();
});
声明类型提交按钮登录
<button type="submit" class="btn btn-primary btn-block btn-lg" id="submitform">Login</button>
并尝试将e.preventDefault()
移动到blurForm();
之前像
$("#FormulirLogin").submit(function(e) {
e.preventDefault()
blurForm();
并确保那些函数CCD_ 3和CCD_。