在我看来,我有链接,模态框和脚本。我的模态上有我的ID,但我无法将其发送到我的控制器上。
链接:
<a href="#myModal" data-toggle="modal" id="<?php echo $salle['id_salle'];?>" data-target="#edit-modal"><span class="glyphicon glyphicon-pencil"></span></a>
我的模态:
<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">×</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>
我的剧本:
$( 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; ?>');
}
});
})
});
在我的控制器中,我定义了一个变量$test
,然后我恢复了它。但我定义了我的变量$ _POST ['id_salle']但无法恢复它。我想将它发送给控制器,然后进行处理,但我不能。
谢谢。
答案 0 :(得分:0)
我的控制器:
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');