weixin_33713350 2013-02-08 14:56 采纳率: 0%
浏览 18

Codeigniter Ajax工具提示

I want to make pop up tooltips with dynamic data from db when cursor hover to link, but I'm doing something wrong. Correct my code please.

My view

    <script type="text/javascript">
        $(document).ready(function() {
            $('.tip').tooltip();
        });
    </script>
    <script type="text/javascript" language="javascript">
        jQuery(document).ready(function(){
       $('#something').mouseover(function(){
        $.ajax({
         url: "<?=base_url();?>aircraft/tip",
         type: 'POST',
         data: {
          'id': $(this).attr("rel"),
         },
         dataType: 'json',
         success: function(aircraft_j) {
                  $('#something').attr('data-original-title',aircraft_j);  
              }
        });
        return false;
       });
      });
      </script>

    <a href="#" data-toggle="tooltip" data-placement="right" id="something" title="" 
data-original-title="" rel="1" class="tip">aircraft</a>

My controller

 function tip() {
    $this->output->enable_profiler(false);
    if($this->input->server('HTTP_X_REQUESTED_WITH') != 'XMLHttpRequest'){ echo "fail. try something else"; return; }
    $this->load->model('aircraft_model');
    $idd = $this->input->post('id');
    $aircraft_j = array();
    $aircraft_j = $this->aircraft_model->get_aircraft_tip($idd);
    echo json_encode($aircraft_j);
    }

My model

 function get_aircraft_tip($idd) {
    $this->db->where('id',$idd);
    $query = $this->db->get('aircraft');
    return $query->row_array();
    }
  • 写回答

1条回答 默认 最新

  • weixin_33712987 2013-02-08 18:38
    关注

    Ok, as you said that you are using bootstrap tooltip. here's how you should do it:

    in your html:

    <a href="#" data-toggle="tooltip" id="something" title="" 
    data-original-title="tooltip data goes here">whatever you want</a>
    

    and as I can see you have no problems with your ajax and CI controller but you have to make a slight change to your success function like this:

    success: function(aircraft_j) {
                      $('#something').attr('data-original-title',aircraft_j);  
                  }
    

    Also: you can read about prop() which might be helpful to you.

    Problems you might face..

    In your CI tip function I see echo json_encode($aircraft_j); so your $aircarft_j variable should be a 'string' data type. As I can see you are returning $query->row_array(); from your model, so you might need to work with it as an array . here you can find a good explanation about that.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料