2014-11-18 4 views
3

Я создал функцию поиска для своей веб-страницы, чтобы она могла обновлять информацию. Когда я ищу запись и обновляю информацию. Затем вернитесь, чтобы снова найти запись, которую показывает исходная информация. Я проверяю базу данных MySQL, и она действительно показывает, что информация не меняется, почему это происходит. Кто-нибудь сталкивался с этой проблемой раньше?Не отображает новые данные после внесения изменений

Вот мой index.php форма

<!DOCTYPE html> 

<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 

    <title></title> 
    <meta content="IE=9" http-equiv="X-UA-Compatible"> 
    <link href="css/style01.css" rel="stylesheet"><!-- Bootstrap --> 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 
</head> 

<body> 
    <h2 style="text-align: center">Inventory Integrity Edit Request 
    Form</h2><br> 
    <br> 

    <div class="wrapper"> 
     <div class="mainContent"> 
      <form class="form-horizontal" method="get"> 
       <div class="form-group"> 
        <br> 
        <br> 
        <label class="col-sm-2 control-label" for="id">Enter 
        Request ID #</label> 

        <div class="input-group col-sm-9"> 
         <input class="form-control" id="id" name="=id" 
         placeholder="Type the id" type="text"> <span class= 
         "input-group-btn"><button class= 
         "btn btn-default btnSearch" type="button"><span class= 
         "input-group-btn"><span class= 
         "input-group-btn"><span class= 
         "input-group-btn"><span class= 
         "input-group-btn"><span class= 
         "input-group-btn"><span class= 
         "glyphicon glyphicon-search">Search</span></span></span></span></span></span></button></span> 
        </div> 
       </div> 
      </form> 

      <div class="col-sm-2"></div> 

      <div class="col-sm-9"> 
       <!-- This table is where the data is display. --> 

       <table class="table table-striped table-hover" id= 
       "resultTable"> 
        <thead> 
         <tr> 
          <th>Id</th> 

          <th>Name</th> 

          <th>lanId</th> 

          <th>Department</th> 

          <th>Manager</th> 

          <th>Work Requested</th> 

          <th>PO</th> 

          <th>IS</th> 

          <th>Request Comments</th> 
         </tr> 
        </thead> 

        <tbody></tbody> 
       </table> 
      </div> 
     </div> 
    </div><!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.10.2.js"></script> 
<!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> <script type="text/javascript"> 
jQuery(document).ready(function($) { 
      $('.btnSearch').click(function(){ 
       makeAjaxRequest(); 
      }); 

      $('form').submit(function(e){ 
       e.preventDefault(); 
       makeAjaxRequest(); 
       return false; 
      }); 

      function makeAjaxRequest() { 
       $.ajax({ 
        url: 'php/search.php', 
        type: 'get', 
        data: {id: $('input#id').val()}, 
        success: function(response) { 
         $('table#resultTable tbody').html(response); 
        } 
       }); 
      } 
     }); 
    </script> 
</body> 
</html> 

Вот моя search.php форма

<?php 

    require_once 'db_connect.php'; 
    $conn = dbConnect(); 
    $OK = true; // We use this to verify the status of the update. 
    if (isset($_GET['id'])) { 
     // Create the query 
     $data = "%".$_GET['id']."%"; 
     $sql = 'SELECT * FROM requests WHERE id like ?'; 
     $stmt = $conn->prepare($sql); 
     $results = $stmt->execute(array($data)); 
     $rows = $stmt->fetchAll(); 
     $error = $stmt->errorInfo(); 
     //echo $error[2]; 
    } 
    // If there are no records. 
    if(empty($rows)) { 
     echo "<tr>"; 
      echo "<td colspan='4'>There were not records</td>"; 
     echo "</tr>"; 
    } 
    else { 
     foreach ($rows as $row) { 
      echo "<tr>"; 
       $id = $row['id']; 
       echo "<td><a href='update.php?id=$id'>$id</a></td>"; 
       echo "<td>".$row['name']."</td>"; 
       echo "<td>".$row['lanId']."</td>"; 
       echo "<td>".$row['department']."</td>"; 
       echo "<td>".$row['mgrname']."</td>"; 
       echo "<td>".$row['work_requested']."</td>"; 
       echo "<td>".$row['purchase_order']."</td>"; 
       echo "<td>".$row['inbound_shipment']."</td>"; 
       echo "<td>".$row['request_comments']."</td>"; 


      echo "</tr>"; 
     } 
    } 
?> 

ответ

3

кэширования отключить Ajax:

$.ajax({ 
    url: 'php/search.php', 
    cache: false, 
    type: 'get', 
    data: { 
     id: $('input#id').val() 
    }, 
    success: function (response) { 
     $('table#resultTable tbody').html(response); 
    } 
}); 


редактировать: из jQuery API docum ентация для jQuery.ajax():

кэша (по умолчанию: правда, ложь для «сценария» DATATYPE и «JSONP»)

+0

Спасибо, сэр, что работал я не знаю Аякса кэширование было включено по умолчанию. – Donny

+0

Я приму свой ответ, как только смогу, он ответит на 6 минут. – Donny

+0

добро пожаловать! и я не был уверен, что он включен по умолчанию, но ваша проблема очень похожа на проблему с кешированием. –

Смежные вопросы