如何解决Yii2将参数从按钮发送到模态ajax
我需要将一个参数从按钮放到小部件
data-video =“ fbnSR-KBOiE”
到'param'=> 42 像这样'param'=> fbnSR-KBOiE
我该怎么做?
echo ModalAjax::widget([
'id' => 'showVideo','header' => 'Create Company',//'toggleButton' => [
// 'label' => 'New Company',// 'class' => 'btn btn-primary pull-right'
//],'url' => \yii\helpers\Url::toRoute(['youtube/index',**'param' => 42**]),// Ajax view with form to load
'ajaxSubmit' => true,// Submit the contained form as ajax,true by default
// ... any other yii2 bootstrap modal option you need
]);
?>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#showVideo" **data-video="fbnSR-KBOiE"** data-backdrop="false">
show video
解决方法
此代码通过ajax通过控制器 youtube / index 将参数从按钮 data-url =“ watch?v = ik7ysDGWbcw” 发送到模态
<span id="play-button" class="fa fa-play-circle play-button" data-toggle="modal" data-target="#youtubeModal" data-url="watch?v=ik7ysDGWbcw" data-backdrop="false">
</span>
<div class="modal fade" id="youtubeModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$('#youtubeModal').on('show.bs.modal',function (event) {
let button = $(event.relatedTarget) // Button that triggered the modal
let youtubeUrl = button.data('url') // Extract info from data-* attributes
$.ajax({
url: '<?= \yii\helpers\Url::toRoute(['youtube/index'])?>',type: 'post',data: {youtubeUrl: youtubeUrl},success(response) {
// Add response in Modal body
$('.modal-body').html(response);
//$('#exampleModal').html(response);
// Display Modal
//$('#exampleModal').modal('show');
}
});
});
</script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。