0

複数の変数をブートストラップモーダルに渡すことはできますか?

ここに私のコード:

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>

リンクをクリックすると、ブートストラップモーダルがポップアップします

<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 に渡すにはどうすればよいですか?

4

2 に答える 2

0

複数のパラメーターを投稿する最も簡単な方法は、オブジェクト リテラルを使用して ajax 呼び出しでデータ要素を設定することです。

data: {
        'post_id':id,
        'myParam':"myvalue",
        'anotherOne':"again"
}

次に、php で $_POST 値としてそれらにアクセスできます。

$post_id = $_POST["post_id"];
$myParam = $_POST["myParam"];
$anotherOne = $_POST["anotherOne"];
于 2013-07-11T05:11:15.020 に答える