how can page reload disabled when data get using ajax success function in javascript codeigniter php? -


i have registration form , want check if registered user try register again show alert window already registered using ajax function.

i have used codeigniter framework.

my function working when alert popup , press ok page reloaded. want disable

my form code:

<form class="modal-content" name="form2" action="<?= $this->config->base_url();?>home/register_user" method="post" onsubmit="return validateregister()">                                               <div class="modal-header">                           <button type="button" class="close" data-dismiss="modal" aria-label="close">                             <span aria-hidden="true">×</span>                           </button>                           <h4 class="modal-title">create account</h4>                         </div>                        <div class="page-content vertical-align-middle" style="display:block;">       <div class="form-group has-error">                     <label class="control-label" for="inputtokenfielderror-tokenfield"> <?php echo validation_errors();  ?></label>                    </div>         <div class="form-group form-material floating">           <input type="text" class="form-control " id="inputname" name="username" value="<?php echo set_value('username'); ?>" autocomplete="off">           <label class="floating-label">username</label>         </div>         <div class="form-group form-material floating">           <input type="email" class="form-control " id="my_email" name="email" value="<?php echo set_value('email'); ?>" autocomplete="off">         <label class="floating-label">email</label>         </div>         <div class="form-group form-material floating">           <input type="password" class="form-control " id="inputpassword" name="password" autocomplete="off">           <label class="floating-label">password</label>         </div>   <div class="form-group">         <button type="submit" class="btn btn-primary btn-block">join - it's free</button>  </div>        </form> 

my javascript function:

function checkregistrations()          {             var email = $('#my_email').val();             $.ajax({                 url: "<?= base_url() ?>home/checkregistration",                 async: false,                 type: "post",                 data: "email="+email,                 datatype: "html",                 success: function(data) {                   //  alert(data);                     if(data==1)                     {                      //event.preventdefault();                     alert('email registered');                     return false;                     window.location.reload(false);                     }                     else{                          return true;                     }                 }             })         } 

you returning true/false inside annon. function i.e. success handler. parent function not returning true/false.

modify code :

function checkregistrations()          {             var email = $('#my_email').val();             var isvalid = true;             $.ajax({                 url: "<?= base_url() ?>home/checkregistration",                 async: false,                 type: "post",                 data: "email="+email,                 datatype: "html",                 success: function(data) {                     if(data==1)                     {                     alert('email registered');                     isvalid = false;                     }                 }             });            return isvalid;         } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -