weixin_33688840 2016-02-13 08:24 采纳率: 0%
浏览 150

将数据附加到Tbody AJAX

I have a foreach statement that is adding the data from a DB to my table rows

HTML

<table id="myTable" class="display table center-table" width="100%" >
   <thead>  
          <tr>  
            <th>Product #</th>  
            <th>Alternate #</th>  
            <th>Description</th>  
            <th>On Hand</th>  
        <th>Condition</th>
          </tr>  
        </thead>  

    <tbody id="productResults"> </tbody>

</table>

PHP

$query =  $sql . " limit " . $start . "," . $perPage; 
  $data = $db_handle->runQuery($query);

  if(empty($_GET["rowcount"])) {
  $_GET["rowcount"] = $db_handle->numRows($sql);
  }
  $pages  = ceil($_GET["rowcount"]/$perPage);
    $output = '';
  if(!empty($data)) {
  $formval = '<input type="hidden" class="pagenum" value="' . $page . '" /><input type="hidden" class="total-page" value="' . $pages . '" />';
  foreach($data as $k=>$v) {
  $output .= '<tr><td>' . $formval . $data[$k]["wuno_product"] . '</td>';
  $formval = '';
  $output .= '<td>' . $data[$k]["wuno_alternates"] . '</td>';
  $output .= '<td>' . $data[$k]["wuno_description"] . '</td>';
  $output .= '<td>' . $data[$k]["wuno_onhand"] . '</td>';
  $output .= '<td>' . $data[$k]["wuno_condition"] . '</td></tr>';     
}
}
echo $output;

Then in my user view I am adding the data back to the page like this,

JQUERY

<script>

(function($) {
$(document).ready(function(){
    function getresult(url) {
    $.ajax({
          url: url,
          type: "GET",
          data:  { rowcount:$("#rowcount").val() },
          beforeSend: function(){
          $('#loader-icon').show();
        },
        complete: function(){
            $('#loader-icon').hide();
        },
        success: function(data){/* convert to dom element */
            $("#productResults").append( data.toElement() );
        },
        error: function(){}             
   });
}

    $(window).scroll(function(){
        if ($(window).scrollTop() == $(document).height() - $(window).height()){
            if($(".pagenum:last").val() <= $(".total-page").val()) {
                var pagenum = parseInt($(".pagenum:last").val()) + 1;
                getresult('<?php echo $assetPath; ?>?page='+pagenum);
            }
        }
    }); 
});
})( jQuery );

</script>

But when it shows up in my page it shows up outside of the table and does not have the html added to it. It looks like this in the page,

8855K5MS21026-B2111212M39029/5-1171313Q4559PROD CODE: 4057911RESTOCKING CHARGE11TAS8732-1C277TEST REPORTS6690H549(W) LAMP CKT99MEC-1MF1 FEET DB9M/F CABLE11T1-GMIL-L-25567E1 GAL JUG2121WL-322914VOLT T-1 BULB100100

Which was the data from the DB just all together... Why would this happen and how can I fix it? It shows up above the table instead.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题