javascript - return false not works for ajax success function in yii -


i want set validation of unique email id in yii not works properly, problem. form code below:

  <div class="row">     <?php echo $form->labelex($model1,'user_email'); ?>     <?php echo $form->textfield($model1, 'user_email', array('maxlength' => 300)); ?>     <?php echo $form->error($model1, 'user_email', array('clientvalidation' => 'js:customvalidateemail(messages,this.id)'), false, true);           $infofieldfile1 = (end($form->attributes)); ?>      <p class="emailuniquecheck" style="margin-left: 24%; color: red;">       </div> 

my ajax code below:

<script> function customvalidateemail(messages,id){     var namec= '#'+id;       var = $(namec).val();     if (a == '') {         messages.push('email id empty.');         return false;     }     var email = $("#registration_user_email").val();     $(".emailuniquecheck").html('<img alt="loader" src="/images/loading.gif" />');     $.ajax({             url:"<?php echo yii::app()->request->baseurl;?>"+"/supplier/checkuniqueemail?email="+a,             data:'req=add_more',             datatype:'html',             type:'post',             async: false,             success:function(resp){                 if(resp == 1) {                 $(".emailuniquecheck").html("email exists.");                 return false;                 } else {                 $(".emailuniquecheck").html("proceed.");                     }              },             error:function(er){                 alert("an error has occured, please reload/refresh page , try again.");             }         }); } 

here, vaidation works empty email means if(a == '') { alert('bla bla'); } , and page not submits on click of submit button.(as required.)

for ajax response validation works return false; not works. , form submits. tried many things not works. can 1 me?

//since call not asynchronous , need return false after ajax call  var isvalid = false; function customvalidateemail(messages, id) { var namec = '#' + id; var = $(namec).val(); if (a == '') {     messages.push('email id empty.');     return false; } var email = $("#registration_user_email").val(); $(".emailuniquecheck").html('<img alt="loader" src="/images/loading.gif" />'); $.ajax({     url: "<?php echo yii::app()->request->baseurl;?>" + "/supplier/checkuniqueemail?email=" + a,     data: 'req=add_more',     datatype: 'html',     type: 'post',     async: false,     success: funsuccess(),     error: funerr() }); return isvalid;  } function funsuccess(data, textstatus, jqxhr) { if (data == 1) {     $(".emailuniquecheck").html("email exists.");     return true; } else {     $(".emailuniquecheck").html("proceed."); } isvalid = true; }  function funerr(err) {    alert("an error has occured, please reload/refresh page , try  again; isvalid = true; } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -