codeigniter - I want to call controller using javascript -


here, using codeigniter. want call controller method using javascript view called. want call view method after 1 second. want call popup dashboard, called using controller. dashboard "user_view.php" . view of "user_home.php", want call "break_alert.php".

here code:

controller:

function alert_breaktime() {      $this->load->view('break_alert'); } 

view:

user_view.php:

<script type="text/javascript">  var timer = settimeout(function() {      alert('adsfadf');     window.location.href = "<?php echo site_url('welcome/alert_breaktime');?>  },1000);   </script> 

break_alert.php:

<script src="<?=base_url()?>resource/js/jquery-2.1.1.min.js"></script>   <div class="modal-dialog">     <div class="modal-content">             <div class="modal-header">                 <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">add activity</h4>             </div>             <?php $attributes = array('class' => 'bs-example form-horizontal'); echo form_open(base_url().'activity/add',$attributes); ?>             <div class="modal-body">                    <div class="form-group">                     <label class="col-lg-2 control-label">subject<span class="text-danger">*</span></label>                     <div class="col-lg-10">                         <input type="text" class="form-control holiday_name"  name="holiday_name" required>                     </div>                 </div>                  <div class="form-group row">                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-phone"></i>&nbsp;call</button>                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-group"></i>&nbsp;meeting</button>                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-tasks"></i>&nbsp;task</button>                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-flag"></i>&nbsp;deadline</button>                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-envelope"></i>&nbsp;email</button>                     <button type="submit" class="btn btn-default col-md-2"><i class="fa fa-cutlery"></i>&nbsp;lunch</button>                  </div>                  <div class="form-group">                     <label class="col-lg-2 control-label">date<span class="text-danger">*</span></label>                     <div class="input-group date col-lg-10" id="datetimepicker5">                         <input ng-model="dt" type='text' class="col-sm-3 form-control" value="" readonly data-date-format="yyyy/mm/dd"/>                             <span class="input-group-addon">                                 <span class="fa fa-calendar"></span>                             </span>                     </div>                 </div>                  <div class="form-group">                    <textarea class="textarea" id="description"></textarea>                 </div>          <div class="modal-footer">                     <a href="#" class="btn btn-default" data-dismiss="modal"><?=lang('close')?></a>                      <button type="submit" class="btn btn-primary">add activity</button>         </div>             </div>      </div> </div> 

in code whole page refresh after every second. in place of "window.location.href" use ajax call , evaluate script code this.

    $.ajax({              url: "your url",              success: function(data){                     $(data).find("script").each(function() {                     eval($(this).text());                   }              }     });      function alert_breaktime()    {       echo $this->load->view('break_alert');    } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -