2012-06-12 18:08
采纳率: 0%
浏览 39




       public function index()
           $data['clienthistory'] = $this->locations_model->get_locations();
           $data['main_content'] = 'dashboard';
           $this->load->view('includes/template', $data);

       public function index2()
          $data['clienthistory'] = $this->locations_model->get_locations();
          return json_encode($data['clienthistory']);                                                                     


 <h2>timer test</h2>
    <?php echo now();?>

<h2>Latest Client Status</h2>
            <?php echo form_open('Dashboard/index');          
            echo form_submit('submit', 'Refresh Client Data', 'id="clientsubmit" class="btn-primary"');
      <div class="row-fluid">
             <div class="span12" id="ajaxcontainer">
               <table class="table table-bordered table-striped">
                   <th>Last Updated</th>
               <?php foreach ($clienthistory as $histitem): ?>
                        <td><?php echo $histitem['network'] ?></td>
                        <td><?php echo $histitem['name'] ?></td>
                        <td><?php echo $histitem['lastupdated'] ?></td>
               <?php endforeach ?>


     <?php echo form_close();  ?>
     <script type="text/javascript">
        $('#clientsubmit').click(function() {                   
                    url:"<?php echo site_url('Dashboard/index2'); ?>",
                    type: 'POST',
                    dataType: 'html'
                    success: function(returnDataFromController) {

       return false;      


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • DragonWar% 2012-06-12 18:16

    Your button is a submit so it will refresh the page when clicked.

    You need to change it to something else, like <a></a> and append a action to it, something like this:

    <a href="#" id="clientsubmit" class="btn btn-primary">Refresh Client Data</a>

    Since you are using twitter bootstrap, the link won't mess with your layout adding a btn to it's class.

    Without the submit button, your page won't be refreshed and your date function will be intact.

    And just for precaution, disable that link/button when clicked until the request is returned.

    $('#clientsubmit').click(function() {
    $(this).attr("disabled", "disabled");

    And on your ajax call you will just update the ajaxcontainer element.

    Hope it helps.

    打赏 评论

相关推荐 更多相似问题