dongyun8075 2018-10-03 11:16 采纳率: 100%
浏览 44

如何切换从AJAX获取的数据?

I have this code in which I am trying to show and hide the data on clicking a product number and the data is being fetched from database through AJAX. I want the data to be shown beneath the desired row. I want to put the data in tbody and show it on clicking its product number.

if (mysqli_num_rows($result) > 0)
{

    while($row = mysqli_fetch_assoc($result))
    {
        ?>
        <tr><td  align="center"><?php  echo $row['FONumber']; ?></td></tr>
        <tbody id='sd'<?php echo $p; $p++; ?>></tbody>
    <?php }
}

Javascript and AJAX:

$(function(){
    $('#hover1').on({
        mouseenter:function(){$(this).css("background","grey")},
        mouseleave:function(){$(this).css("background","white")}},'tr');

});

// number of tds
var c = $('#hover1').find('td').length;

var id = document.getElementById("hover1");

for(var i = 0; i < c; i++){

    id.rows[i].onclick=(function(){
        var a = $(this).find('td:eq(0)').text();
        $.ajax({
            url: 'printpo1.php',
            type: 'post',
            data: {fo:a},
            success: function(data){
                $('#name').html(data);
            }
        });
        $('#sd'+i).toggle();
        alert('#sd'+i);
    });  
}

So far the data I am trying to fetch is showing in the tbody of the first row. Any help will be really appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?