php – 动态地将信息加载到Twitter Bootstrap模式

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 动态地将信息加载到Twitter Bootstrap模式脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
问题:

我想通过使用jquery将链接属性中的值传递给PHP / SQL查询.

HTML代码

<a data-toggle="modal" href="#myModal" id="1"><i class="pull-right icon-eye-oPEn"></i>HTML</a>

PHP代码

<div id="myModal" class="modal hide fade">
    <div class="modal-header">
      <button class="close" data-dismiss="modal">&amp;times;</button>
      <h3>TITle</h3>
    </div>
    <div class="modal-body">            
        <?PHP
            $query = "SELECT * From table WHERE id = ID From JQUERY HERE";
            $result = MysqL_query($query) or die ('Error (' . MysqL_errno() . ') ' . MysqL_error());
        ?>
    </div>
    <div class="modal-footer">
      <a href="#" class="BTn btn-info" data-dismiss="modal" >Close</a>
    </div>
</div>

场景:

用户单击具有data-toggle =“modal”的链接元素时,jQuery应该使用id属性(在这种情况下为1)的值,并将其发送到SQL查询,以便SQL查询将看起来像:

$query = "SELECT * FROM table WHERE id = 1";

jQuery代码

$("a[data-toggle=modal]").click(function(){
    VAR essay_id = $(this).attr('id');
    //Find $essay set it to essay_id in PHP
    //Alternatively create a $_SESSION['eiD'] here
});

题:

如何使用jQuery在PHP中设置变量($essay)?或者如何通过jQuery在PHP中创建会话变量?

这里是解决方案,
<a href="#" id="1" class="push">click</a>

在你的模态身上使用一个div,就像这样

<div class="modal-body">  

             <div class="something" style="display:none;">
                    // here you can show your output dynamically 
             </div>
    </div>

现在把数据放入带有ajax调用.something中.please检查http://api.jquery.com/jQuery.ajax/了解更多关于jquery ajax的信息.

$(function(){

   $('.push').click(function(){
      var essay_id = $(this).attr('id');

       $.ajax({
          type : 'post',url : 'your_url.PHP',// in here you should put your query 
          data :  'post_id='+ essay_id,// here you pass your id via ajax .
                     // in PHP you should use $_POST['post_id'] to get this value 
       success : function(r)
           {
              // Now you can show output in your modal 
              $('#mymodal').show();  // put your modal id 
             $('.something').show().html(r);
           }
    });


});

   });

脚本宝典总结

以上是脚本宝典为你收集整理的php – 动态地将信息加载到Twitter Bootstrap模式全部内容,希望文章能够帮你解决php – 动态地将信息加载到Twitter Bootstrap模式所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。