将值从引导数据id传递到php变量

将值从引导数据id传递到php变量,php,jquery,twitter-bootstrap,modal-dialog,Php,Jquery,Twitter Bootstrap,Modal Dialog,我有一个带有几个月值的下拉菜单。这是其中一个例子 <li data-toggle="modal" data-id="January" class="random " href="#AddMonth">January</li> 一月 我想将“一月”值传递给php变量。像这样的 <div class="modal fade" id="AddMonth" tabindex="-1" role="dialog" aria-labelledby="myModalLabel

我有一个带有几个月值的下拉菜单。这是其中一个例子

<li data-toggle="modal" data-id="January" class="random " href="#AddMonth">January</li>
  • 一月
  • 我想将“一月”值传递给php变量。像这样的

    <div class="modal fade" id="AddMonth" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Update your information</h4>
      </div>
      <div class="modal-body">
          <?php
             // $month  = ? // month will contain the variable that was pass from data-id
             MethodSendMonthData($month);
    
           ?>
      </div>
    </div>
    
    
    &时代;
    更新您的信息
    


    我不知道如何才能做到这一点?

    请详细说明我之前的评论

    您可以使用,甚至可以实现这一点

    例如,元素的id为
    mymonth

    <li id="mymonth" data-toggle="modal" data-id="January" class="random " href="#AddMonth">January</li>
    
    如您所见,我们获取属性
    数据id
    ,并将其存储在
    val
    变量中。然后将其发布到示例php文件:
    myphpfile.php

    myphpfile.php
    将具有您的php函数(当然是一个示例):

    
    
    PHP是服务器端语言
    ,而
    HTML是客户端语言
    。这意味着如果没有javascript,即ajax请求,您无法将选择中的
    数据id
    传递给php变量。我如何使用ajax请求呢?或者它是我可以在线查看的地方吗?@user3530310搜索框在页面的右上角。如果你感兴趣的话,谷歌也可能有大约8000万条搜索结果。
    $(document).on('click', 'li#mymonth', function(){
        // get month
        var val = $(this).attr('data-id');
    
        $.post('myphpfile.php', {month: val}, function(data){
            console.log(data);
        });
    });
    
    <?php 
    
    if(isset($_POST['month']) && !empty($_POST['month'])) {
        // do your sanatizing and such....
        // do your php stuff
        MethodSendMonthData($month);
    
       // you can echo back what you need to and use that in jquery as seen above
    }
    
    ?>