将多个变量传递给引导模态 [英] pass multiple variable to bootstrap modal

查看:71
本文介绍了将多个变量传递给引导模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将多个变量传递给自举模式吗?

can I pass multiple variable to bootstrap modal?

这是我的代码:

p>Link 1</p>
<a data-toggle="modal" id="1" class="push" href="#popresult">test</a>
<p>&nbsp;</p>
<p>Link 2</p>
<a data-toggle="modal" id="2" class="push" href="#popresult">test</a>

点击链接将弹出一个引导程序模式

click the links will pop up a bootstrap modal

<div class="modal hide" id="popresult">
  <div class="modal-header">
    <button class="close" data-dismiss="modal">×</button>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body" style="display:none;">
    <p>some content</p>

  </div>
  <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Close</a> <a href="#" class="btn btn-primary" >View full result</a> </div>
</div>

这里是ajax代码:

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

       $.ajax({
          type : 'post',
           url : 'yourScript.php', // in here you should put your query 
          data :  'post_id='+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 
             $('.modal-body').show().html(r);
           }
      });
   });
});

ajax代码会将变量发布到另一个php文件yourScript.php

ajax code will post variable to another php file yourScript.php

<?php
 session_start();
     $_SESSION['myId'] = $_POST['post_id'];
     echo $_SESSION[myId];
?>

如何将多个变量传递给yourScript.php?

how can I pass multiple variables to yourScript.php?

推荐答案

您可以传递多个这样的变量

You can pass multiple variables like this

var param1 = 2;
var param2 = 5;

var data = 'param1='+param1+'&param2='+param2;

$.ajax({
         type: "POST",
         url: "yourScript.php",
         data: data,
         success: function(html){

         }
       });

请参见此示例,如果您想从<a>标记中获取更多数据而不是仅获取id

SEE THIS EXAMPLE if you want to get more data from <a> tag instead of getting only the id

这篇关于将多个变量传递给引导模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆