尝试检查电子邮件ID是否已存在,这里的查询工作正常,而ajax正常工作,但是我无法提交表单。
这里我正在使用$('#form1').submit();提交表单,但仍然没有错误,并且表单没有提交
<form method="post" id="form1" action="practice2.php" class="form-horizontal">
user id:<input type='text' name='user_id'/>
email id:<input type='email' id="email" name='email'/>
password:<input type='password' id="pass" name='pass'/>
<div id="res" style=" color:red;"></div>
<input type='button' name='submit' id="btn" value='register'/>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js" integrity="sha384-7aThvCh9TypR7fIc2HV4O/nFMVCBwyIUKL8XCtKE+8xgCgl/PQGuFsvShjr74PBp" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#btn').on('click',function(){
var email=$('#email').val();
if(!email==""){
$.ajax({
type:'POST',
url:'practice2.php?action=check',
data:'email='+email,
success:function(data){
if(data=="true"){
alert(data);
$( '#form1' ).submit();
}else{
$('#res').html(data);
return false;
}
}
});
}
});
});
</script>
功能
function select1($mail){
$sth = $this->dbh->prepare("SELECT * FROM `user_detail` WHERE email_id= :email");
$sth->bindParam(':email', $mail);
$sth->execute();
$result=$sth->fetchAll();
return $result;
}
答案 0 :(得分:0)
你可以这样尝试吗?
$('#btn').on('click',function(){
var email=$('#email').val();
if(!email==""){
MyForm = $('#form1');
$.ajax({
type:'POST',
url:'practice2.php?action=check',
data:'email='+email,
success:function(data){
if(data=="true"){
alert(data);
MyForm.submit();
}else{
$('#res').html(data);
return false;
}
}
});
}
});