简体   繁体   中英

Refresh panel javascript on refresh

I need to reload my panel contents via javascript. I have two sections in my web page: a) A list of products and b) A panel with product description. When user clicks on a product I display a panel which reads database information using php code using the variable I passed via product click. (panel-id). I pass the panelId to a javascript which displays a modal notifying user a db read is happening and after that it needs to reload the panel contents with new info. What is the method I need to use to refresh this panel so it is forced to read the new value of php variable? show/hide doesn't seem to do the trick.

Javascript:

$('#getInfoModal').on('show.bs.modal', function(e) {

    var panelId = $(e.relatedTarget).data('panel-id');

    //console.log('Progress bar modal calling: ' + panelId);
    // Hide previous modal if any
    $('#main_panel').parent().hide();
    $('#modalProgressBar').progressbar('reset');

    // Emulate delay and close after progress bar finish
    setTimeout(func, 4000);
        function func() {

            $('#getInfoModal').modal('hide');
            $('#main_panel').parent().show(); // Method to force panel reload?
            $('.modal-backdrop').remove();              
    }

    setTimeout(function(){
       $('#modalProgressBar').progressbar(100);
    }, 1000);

});

HTML code:

   <div class="col-lg-14">                  
                  <!-- START panel-->
                  <div id="main_panel" class="panel panel-default panel-demo">
                  <div class="panel-footer">
                  <div class="media">                                                       
                     <em class="fa fa-tasks fa-1x text-success"></em>
                     <strong>Device status</strong>
                     <a href="#" data-perform="panel-collapse" data-toggle="tooltip" title="Collapse Panel" class="pull-right">
                     <em class="fa fa-minus"></em>
                     </a>
                     <a href="#" data-perform="panel-refresh" data-spinner="traditional" data-toggle="tooltip" title="Refresh Inventory" class="pull-right">
                        <em class="fa fa-refresh"></em>
                     </a>
                  </div>                  
                  </div>
                  <div class="panel-body">                                       
                  <div class="panel-group">

                  <!-- START row--> 
                  <div class="row" >
                     <div class="col-lg-6" >                                                                   
                           <!-- START panel-->
                           <div class="panel panel-info">
                              <div class="panel-heading"><em class="fa fa-barcode"></em> Serial number: <strong><?php echo $panel_id?></strong>                                 
                              </div>
                                 <div class="panel-body">
                                 <div class="media">
                                 <div class="pull-left">   
                                 <img src="app/img/switch4ports.png" alt="Image" width="150" height="100" data-toggle="tooltip" data-placement="left" title="2 ports connected" class="media-object">                                                            
                                 </div>                                 
                                 </div>
                                  <table id="table-ext-1" class="table">
                                    <thead>
                                    </thead>
                                    <tbody>
                                       <class="text-left">
                                       <tr>
                                        <!-- Yes, SQL injection is possible. Need refactoring--> 
                                       <td><small><em class="fa fa-check-circle-o text-success"></em><strong> WAN IP Address/Mask:<class="text-muted"></strong> <?php echo data_instance_model($dbc,'wanipaddr',$panel_id)?>/<?php echo data_instance_model($dbc,'wanmask',$panel_id)?></small></td>
                                       <td><small><em class="fa fa-check-circle-o text-success"></em><strong> WAN Default Gateway:<class="text-muted"></strong> <?php echo data_instance_model($dbc,'wangateway',$panel_id)?></small></td>
                                       </tr>
                                       <tr>
                                       <td><small><em class="fa fa-check-circle-o text-success"></em><strong> LAN IP Address/Mask:<class="text-muted"></strong> <?php echo data_instance_model($dbc,'lanipaddr',$panel_id)?></small></td>
                                       </tr>                          
                                    </tbody>
                                  </table>
                                 </div>                          
                           </div>
                        </div><!-- END panel-->                                 
                     </div> 
                  </div>

To refresh your modal below command is enough

$('#getInfoModal').modal("show");

But As far as I understood , you wanted to update the panel body.So what you do is place a div inside your panel body and update it with the content you get from ajax.

For example

 <!-- START panel-->
<div class="panel panel-info">
    <div class="panel-heading"><em class="fa fa-barcode"></em> Serial number: <strong><?php echo $panel_id?></strong> 
    </div>
    <div class="panel-body">
        <div class="media">
            <div class="pull-left">
                <img src="app/img/switch4ports.png" alt="Image" width="150" height="100" data-toggle="tooltip" data-placement="left" title="2 ports connected" class="media-object">
            </div>
        </div>
        <div id="tablecontents"></div>
    </div>
</div>
</div>
<!-- END panel-->

So assuming you getting cotents from server as json , Loop the json and update the table in tablecontents

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