我可以将多个变量传递给引导模式吗?
这是我的代码:
p>Link 1</p>
<a data-toggle="modal" id="1" class="push" href="#popresult">test</a>
<p> </p>
<p>Link 2</p>
<a data-toggle="modal" id="2" class="push" href="#popresult">test</a>
单击链接将弹出一个引导模式
<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
<?php
session_start();
$_SESSION['myId'] = $_POST['post_id'];
echo $_SESSION[myId];
?>
如何将多个变量传递给 yourScript.php?