weixin_33736832 2017-02-02 16:36 采纳率: 0%
浏览 76

在MVC上的模态框上发送数据

In my view I have the link, the modal box, and script. I have my ID on my modal but i can't send it on my controller.

The link:

<a href="#myModal" data-toggle="modal" id="<?php echo $salle['id_salle'];?>" data-target="#edit-modal"><span class="glyphicon glyphicon-pencil"></span></a>

My modal:

<div id="edit-modal" class="modal fade" 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">Modal title</h4>
        </div>
        <div class="modal-body edit-content"></div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
    </div>
</div>

And my script:

$( document ).ready(function() {
  $('#edit-modal').on('show.bs.modal', function(e) {
    var $modal = $(this),
    Id = e.relatedTarget.id;
    $.ajax({
      method: 'POST',
      url: 'index.php?section=gestion-salles',
      data: 'id_salle='+Id,
      success: function(data) {
        alert(data);
        $modal.find('.edit-content').html(Id + '<?php echo $test; ?> ' + 'id= <?php echo $id; ?>');
      }
    });
  })
});

In my controller I defined a variable, $test, and I recovered it. But I defined my variable $_POST['id_salle'] but can't recover it. I would like to send it to the controller and then do the processing but I can't.

Thank you.

  • 写回答

1条回答 默认 最新

  • weixin_33725272 2017-02-03 08:16
    关注

    My controller:

    include_once('modele/set_salles.php');
    include_once('modele/get_salles.php');
    include_once('controleur/modal.php');
    if(isset($_POST['bouton']))
    {
       if($_POST['titre'] !='' && $_POST['description'] !='' && $_POST['adresse'] !='' && $_POST['cp'] !=''){
            $tmp_name = $_FILES["photo"]["tmp_name"];
            $name = $_FILES["photo"]["name"];
    set_salles(addslashes($_POST['titre']), addslashes($_POST['description']), $name, $_POST['pays'], $_POST['ville'], addslashes($_POST['adresse']), $_POST['cp'], $_POST['capacite'], $_POST['categorie']);   
            $uploads_dir = 'img/';
            move_uploaded_file($tmp_name, "$uploads_dir/$name");
        } else {
            $remplir = '<p style="color:red">merci de remplir tous les champs</p>';
        }
    }
    $salles = get_salles();
    foreach($salles as $cle => $salle)
    {
    $salles[$cle]['titre'] = htmlspecialchars($salle['titre']);
    $salles[$cle]['description'] = nl2br(htmlspecialchars($salle['description']));
    }
    $id = $_POST['id_salle'];
    $test = 'Hello';
    // On affiche les page (vues)
    include_once('vue/include/header.php');
    include_once('vue/include/navbar.php');
    include_once('vue/gestion-salles.php');
    include_once('vue/include/footer.php');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用