dsbruqxgt820011351 2017-03-14 13:34
浏览 20
已采纳

Laravel ajax模特展示帖子

I have a foreach() from database table, I want to show a popup/model to show its extra information.

I am showing just title and description and on click i want to open up a popup and show its extra information.

@foreach($myProjects as $project)
    <div class="col-sm-4 col-md-4 notes notes--blue">
        <a href="#edit-note" data-toggle="modal" style="background-color: #f9f9f9;border-bottom: 5px solid #42A5F5">
            <div class="notes__title">{{$project->title}}</div>
            <div class="notes__body">{{$project->description}}</div>
        </a>
        <div class="notes__actions" data-demo-action="delete-listing">
             <i class="zmdi zmdi-delete"></i>
        </div>
        <div class="notes__actions1" data-demo-action="delete-listing">
              <i class="zmdi zmdi-edit"></i>
        </div>
        <div class="notes__actions2" data-demo-action="delete-listing">
              <i class="zmdi zmdi-eye"></i>
        </div>
    </div>
@endforeach

I am completely blank, Should i fetch post id to a hidden html tag and on model button click an ajax call will fetch the record info based on the id ?

  • 写回答

1条回答 默认 最新

  • douerqu2319 2017-03-14 13:41
    关注

    I would add a data-id attribute to one of the elements, possibly the wrapper, then add something like

    $(document.body).on('click', '.clickable_element', function(e){
      if ($(this).data('id')) {
            $.ajax({
               url : 'your detail url', 
               data: { id: parseInt( $(this).data('id'), 10 ), 
               success : function(response){
                   // open popup and add response into it.
               }
            })
      }
    

    });

    Update

    I just noticed you already have bootstrap modal there.

    you can add your data-id to data-toggle element then in javascript

    $('[data-toggle=modal]').on('shown.bs.modal' , function(){
      // do your ajax stuff
      // add response in `.modal-body`
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数