douyingp82418 2018-02-02 00:22
浏览 475

在bootstrap popover中加载动态内容

im using datatables, and this is my some of my code for fetching the data for datatables, this works fine now what i want is to load dynamic content on when someone hover or click the anchor tag... this the image datatables data

foreach($result as $row)
{
    $sub_array = array();
    $sub_array[] = '<a href="#" class="hover" id="'.$row['id'].'">'.clean($row["f_name"])." ".clean($row["m_name"])." ".clean($row["l_name"]).'</a>';
    $sub_array[] = strtoupper($row["sex"]);
    $sub_array[] = $row["birthdate"];
    $sub_array[] = $row['age'];
    $data[] = $sub_array;
}

this is what i have tried, still the bootstrap popover not working

$('.hover').popover({
      title:fetchData,
      html:true,
      placement:'right'
    });

    function fetchData(){
      var fetch_data='';
      var element = $(this);
      var id = element.attr("id");

      $.ajax({
        url:"../controller/fetch_single.php",
        method:"POST",
        async:false,
        data:{id:id},
        success:function(data){
          fetch_data = data;
          alert(data);
        }
      });
      return fetch_data;
    }

this is the code that i used for my ajax

//fetch_single.php
    if(isset($_POST["id"]))
    {
        $output = '';
        $statement = $connection->prepare(
            "SELECT id, sex, f_name, m_name, l_name, birthdate,image_name,house_num,street TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) as age from rec_personal WHERE id='".$_POST['id']."'"
            );
        $statement->execute();
        $result = $statement->fetchAll();

        foreach ($result as $row) {
            $output = '
                <p><img src="../upload/'.$row["image_name"].'" class="img-responsive img-thumbnail" /></p>  
                <p><label>Name : '.$row['f_name'].'</label></p>  
                <p><label>Address : </label><br />'.$row['house_num'].'</p>  
                <p><label>Gender : </label>'.$row['sex'].'</p>  
                <p><label>Age : </label>'.$row['age'].' Years</p>  

            ';
        }
        echo $output;
    } 

EDIT this is my reference for the code http://www.webslesson.info/2016/11/php-ajax-jquery-load-dynamic-content-in-bootstrap-popover.html

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?