簡體   English   中英

如何在Codeigniter中使用jquery刷新同一頁面中的div數據表?

[英]How to refresh div data table in same page with jquery in Codeigniter?

如何使用jQuery刷新同一頁中的數據表?

  <!-- reload data table --> $.ajax({ success: function(response){ $(".container").text(response); } }); } 
  <!-- reload data table --> <!-- Table --> <div class="container"> <div class="panel panel-default"> <div class="panel-body"> <?php if ( !empty($log) ) { echo '<div class="table-responsive table-striped">'; echo '<table class="table"> <thead> <tr> <th class="text-center">Time</th> <th class="text-center">Type</th> <th>Details</th> </tr> </thead>'; echo '<tbody>'; foreach ($log as $value) { echo '<tr>'; echo '<td>'.$value['time'].'</td>'; switch($value['severity']) { case 'Error': $button_type = 'btn-danger'; break; case 'Warning': $button_type = 'btn-warning'; break; case 'Notice': $button_type = 'btn-default'; break; } echo '<td><button class="btn btn-xs '.$button_type.' btn-block" disabled>'.$value['severity'].'</button></td>'; echo '<td>'.$value['error'].'</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; echo '</div>'; } elseif ( $log_threshold < 1 && empty($logs) ) { // the setting in config are not correct echo 'Please change the setting $config["log_threshold"] = 1 in config/config.php'; } elseif ( $log_threshold >= 1 && empty($logs) ) { // there are no logs echo 'No log files found'; } else { echo '<div class="table-responsive table-striped">'; echo '<table class="table"> <thead> <tr> <th class="text-center">Time</th> <th class="text-center">Type</th> <th>Details</th> </tr> </thead>'; echo '<tbody>'; echo '<tr> <td colspan=3 style=text-align:center;>No errors or warnings, please set hide_notices to false if you want to view notices</td>'; echo '</tr>'; echo '</tbody>'; echo '</table>'; echo '</div>'; } ?> <!-- Table --> </div> </div> </div> 

下面的代碼datepicker:

<!-- Datepicker -->
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#txtDate").datepicker({
      dateFormat:'yy-mm-dd',
      onSelect: function(tgl) {
        var url = "<?php echo $url; ?>";
        window.location=url + '?log_date=' + tgl
      }
    });

   $('#txtDate').focus(function() {

     $(this).datepicker("show");

     setTimeout(function() {

       $('#txtDate').datepicker("hide");

       $('#txtDate').blur();

     }, 10000)

   })
  });
  </script>

</head>
</html>
<!-- Datepicker -->

我有頁面內容數據表,我想刷新該表但不工作,我不知道要在同一頁面中刷新的代碼jQuery,沒有加載另一頁面,而是在同一頁面中刷新php,我在google中搜索但不工作
如何刷新下面的表div?

您需要在datepicker id上觸發ajax或對您在HTML代碼中設置的內容進行分類。

假設您的日期選擇器的ID為dp

$('#dp').datepicker({
        //other settings
        onSelect: function (date) {
           $.ajax({
               //your ajax code
           })
        }
    });

如果要在ajax調用后更新div,請給div一個id

    $.ajax({
     success:function(response){
      $("#content").html(response);
     }    
   })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM