php - Unable to GET Data from mysql with AJAX call -


i'm having trouble trying data database. code retrieve first row of data database. data correct not matter information put html input field data same in new row added. resolving fantastic.

if going point out have both "post" , "get" mixed in code, understand being possible problem, neither when matching retrieve data db, other first row of data in table.

any great!!! provide answer in advance.

my html code:

index.php

    <div class="row">         <div class="col-md-1"></div>             <div class="col-xs-3">             <h3 class="h4 text-center"><input type="text" name="barcode" id="barcode" size="90" class="col-md-9" value="" method="get" placeholder="barcode / product name"></h3>               </div>         </div>     <br />     <div class="row">         <div class="col-md-1"><p class=""></p></div>         <div class="col-md-6">             <table id="report" class="table table-bordered table-hover">                 <thead>                     <tr>                         <td>sku</td>                         <td>model</td>                         <td>item description</td>                         <td>qty</td>                     </tr>                 </thead>                 <tbody>                  <?php get_item(); ?>                 </tbody>             </table>        </div>     </div> 

this ajax script

<script> var inp = $("#barcode"); // #txt id of textbox  $("#barcode").keyup(function (event) { if (event.keycode == 13) {     if (inp.val().length > 0)     {         $.ajax({             url: "index.php",             type: "get", //also tried post method. didn't work either             data: {id: inp.val()},             success: function(response)             {                 values = response.split(' - ');                 $('#report tr:last').after(                     "<tr class='table-row'>" +                     "<td class=''>" + values[1] + "</td>" +                     "<td class=''>" + values[2] + "</td>" +                     "<td class=''>" + values[3] + "</td>" +                     "<td class=''>" + values[4] + "</td></tr>");             }});     }     $('input[name=barcode]').val('');     }   }); </script> 

here php code

function get_item(){ global $con;     if(!empty($_post)) {     $query = query("select * items");         confirm($query);     while($row = fetch_array($query)) {         $sku = $row['sku'];         $model = $row['category'];         $desc = $row['description'];         $qty = $row['qty'];      echo($id.' - '.$sku.' - '.$model.' - '.$desc.' - '.$qty);     die();     } } } 

move die(); function call out of while loop. gets called rigth @ end of first loop terminating php script.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -