简体   繁体   中英

How do I close Modal Popup on form submit?

I have a modal popup to change the password and I need to close it on submit button.

<div class="modal-body"> 
    <?php if(isset($message))echo '<span class="text-success txt-upper" style="margin-left:2rem;">'. $message .'</span>';?>

    <?php echo form_open('',array('class'=>'ajaxForm')); ?>
      <fieldset class="table "> 
        <div class="form-group">
        <?php $class = form_error('newpassword')?"input-error":"" ?>
          <div  class="col-md-12" style="margin: 10px 0"><?php echo form_password('newpassword','','class="form-control margin-both-0 '. $class.'" id="newpassword"  placeholder="New Password" autocomplete="off"'); ?><?php echo form_error('newpassword'); ?></div>            
        </div>
        <div class="form-group">
        <?php $class = form_error('conpassword')?"input-error":"" ?>
          <div class="col-md-12 " style="margin: 10px 0"><?php echo form_password('conpassword','','class="form-control  margin-both-0 '. $class.'" id="conpassword"  placeholder="Confirm Password" autocomplete="off"'); ?><?php echo form_error('conpassword'); ?></div>           
        </div>  

</div>
<div class="modal-footer">
        <?php echo form_submit('submit_btn', 'Change Password', 'class="submit btn btn-success margin-left-4p pad-1-rem margin-bottom-10"'); ?>
     </fieldset>
    <?php echo form_close();?>  
  </div>

The above code is the form submit button.

$(function() {
        $(".submit").click(function(e){
            var sdata = $('.ajaxForm').serialize();
            $.ajax({
                type: "POST",
                data:sdata,
                url: "<?php echo site_url('home/change_password'); ?>",
                success: function(data){
                    $('#baseModal-xs .modal-content').html(data);  
                }
            });
            return false;
        });
    });

<script type="text/javascript">
    $(".submit").ajaxForm(function() { 
        window.close();
    });

This is the javascript I have added the windows.close function isn't working

From your code it seems like you are using twitter-bootstrap-3. Then, I would stick to their API suggested here: Bootstrap JavaScript Modals and call the modal method to close/hide the visible modal:

$('.modal').modal('hide');

只需调用以下代码

$.modal.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM