帮助,我很绝望。我已经阅读了所有主题,或多或少地解释了我在寻找什么,但仍然被卡住了。
我有一个文件text.php,其中包含:
<a href="#" class="btn" id="openBtn" data-id="<?=$elements['ElementModuleID']?>">Open modal</a>
<div class="modal fade" id="myAjaxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"> <a href="#" class="close" data-dismiss="modal" aria-hidden="true"><span>close</span>×</a>
<div class="title-box">
<h4 class="title"></h4>
</div>
</div>
<div class="modal-body">
<p>My modal content here…</p>
</div>
</div>
</div>
</div>
<script>
$('#openBtn').click(function() {.....
----here i should probably pass ElementID, but how ?
$('.modal-body').load('<?php URL_ROOT?>/modals/uploader.php', function(result) {
$('#myAjaxModal').modal({
show: true
});
});
});
</script>
文件uploader.php包含:
<form action="" method="post" enctype="multipart/form-data" id="FormUploadElementMainImage">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal" aria-hidden="true"><span><?php echo $lang["close"]; ?></span>×</a>
<div class="title-box">
<h4 class="title">Upload Image <?php echo $elements['ElementTitle']; ?></h4>
</div>
</div>
<div class="modal-body">
<input type="text" name="elementID" class="form-group" id="elementID" value="<?=$elements['ElementModuleID']?>" />
<label for="ElementMainImage">
<?php echo $lang[ "pleaseclickbrowse"]; ?>:</label>
<input type="file" name="ElementMainImage" id="ElementMainImage" value="">
<br>
<script>
$("#ElementMainImage").fileinput({
'showUpload': false,
showCaption: false,
'previewFileType': 'any'
});
</script>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
<?php echo $lang[ "buttoncancel"]; ?>
</button>
<button type="submit" name="ButtonUploadMainImage" value="Submit" id="ButtonUploadMainImage" class="btn btn-primary">
<?php echo $lang[ "startupload"]; ?>
</button>
</div>
</form>
简单的任务是在文件uploader.php中检索$ elements ['ElementTitle']和$ elements ['ElementID']。我怎样才能正确传递? 你觉得,我可以让它上班吗?没有! :-)有点惭愧,因为我确信它只需要一点修改。有人可以帮忙吗?非常感谢你
答案 0 :(得分:1)
您可以使用load()
的第二个参数
var data = {
elementTitle: "<?=$elements['ElementTitle']?>",
elementModuleID: "<?=$elements['ElementModuleID']?>"
};
$('.modal-body').load('<?php URL_ROOT?>/modals/uploader.php', data, function(result) {
$('#myAjaxModal').modal({
show: true
});
});
然后在uploader.php
中你会像这样检索它:
<?php echo $_POST['elementTitle']; ?>
<?php echo $_POST['elementModuleID']; ?>