【问题标题】:Modal to show upon redirect (Laravel)重定向时显示的模态(Laravel)
【发布时间】:2022-04-26 13:57:28
【问题描述】:

我正在尝试在重定向到页面时显示模式。

我正在关注此回复 (Laravel how to redirect back to boostrap modal dialog window)

我的控制器:

return redirect('postings')->with('welcome_msg');

我的看法:

@if(Session::has('welcome_msg'))        
<script>
$(function() {
$('#myModal').modal('show');
});
</script>
@endif

<div class="modal fade" id="myModal role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</div>

但是,弹出窗口时不显示模式。我究竟做错了什么?

【问题讨论】:

  • 在 @if(Session::has('welcome_msg')) 之后尝试执行 {{dd()}} 以检查您是否真的有会话。
  • 在浏览器控制台输入你的错误信息

标签: laravel bootstrap-modal


【解决方案1】:
<div class="modal fade" id="myModal role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</div>

@if(Session::has('welcome_msg'))        
<script>
$(function() {
$('#myModal').modal('show');
});
</script>
@endif

这可能会解决它。 HTML 必须在 javascript 之前加载。

【讨论】:

  • 不幸的是它仍然没有显示。我更新了我的代码: return redirect('postings')->with('welcome_msg', 'hello');测试会话,并查看在模态
    ...消息显示但弹出窗口没有
  • @jlim try
  • @jlim 你搞定了吗?
  • 【解决方案2】:

    在 &lt;/ body&gt; 的结束标记之前在您的刀片中尝试此操作

    @if (session()->has('welcome_msg'))
        <script>
            $('#YourModalName').modal('toggle');
        </script>
    @endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多