Yii2 将参数从按钮发送到模态-ajax
Yii2 Send parameters from button to modal-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
此代码将参数从按钮 data-url="watch?v=ik7ysDGWbcw" 通过控制器 youtube/index 来自 ajax
<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>
我需要将一个参数从按钮放入小部件
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
此代码将参数从按钮 data-url="watch?v=ik7ysDGWbcw" 通过控制器 youtube/index 来自 ajax
<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>