[英]form validation ajax submit
我有一个表格。 我需要设置表单验证输入
<input type="text" name="telefon" required="" placeholder="Telefon numaranız" class="form-control">
但是当我单击提交表单为空或不为空发送时。 这是我的JavaScript代码
<script>
function uyem() {
jQuery.ajax({
type: 'POST',
url: 'src/ajax/kayit.php',
data: $('#uyelik-formu').serialize(),
error:function(){ $('#sonuc').html("Bir hata algılandı."); },
success : function (sonuc){
if(sonuc == 'msms'){
$("#mod-sms").modal('show');
}
if (sonuc == 'hatak'){
$("#sonuc").html('<div role="alert" class="alert alert-danger alert-icon alert-icon-colored alert-dismissible"><div class="icon"><span class="mdi mdi-close-circle-o"></span></div><div class="message"><button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true" class="mdi mdi-close"></span></button><strong>Hata!</strong> E-posta yada telefon başka bir üye tarafından kullanılmakta.</div></div>');
}
if(sonuc == 'error'){
$("#mod-error").modal('show');
setTimeout(function() { location.reload() },4000);
}
if (sonuc == 'hata'){
$("#sonuc").html('<div role="alert" class="alert alert-danger alert-icon alert-icon-colored alert-dismissible"><div class="icon"><span class="mdi mdi-close-circle-o"></span></div><div class="message"><button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true" class="mdi mdi-close"></span></button><strong>Hata!</strong> Geçerli bir e-posta ve telefon numarası giriniz.</div></div>');
}
}
});
}
</script>
您必须告诉您的表单是否需要提交。
<form onSubmit="uyem()"></form>
function uyem() {
$.ajax({});
return false;
}
返回false
表示不提交表单,而true
表示提交。
$(function() {
$('form').submit(function(e) {
e.preventDefault();
var data = $('input[name="telefon"]').val();
if(data.length > 0)
{
function uyem()
}
else
{
alert('Input are not valid');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.