duanmiexi2275 2019-08-10 12:42
浏览 86

laravel:如何设置打开模态的会话

I have 2 buttons for 2 modals . in below code :

<div>
    <h3>1 month</h3>
    <button type="button" class="pay-btn-1" data-toggle="modal" data-target="#modal1">Pay this featur</button>
</div>

<div>
    <h3>2 month</h3>
    <button type="button" class="pay-btn-2" data-toggle="modal" data-target="#modal2">Pay this featur</button>
</div>

I insert 2 modals in the footer :

<------ Modal 1------->
    <div id="modal1" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <?php
            Session::flush('month');
            Session::put('month', 1);
            ?>
            <!-- Modal content-->
            <div class="modal-content">
                <form action="{{ route('panel.vip.payment') }}" method="post">
                    @csrf
                    <input type="hidden" value="1" name="plan">
                    <div>
                        <button type="submit">pay</button>
                    </div>
                </form>

                <button type="button" data-dismiss="modal">close</button>
            </div>

        </div>
    </div>

<------ Modal 2------->
    <div id="modal2" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <?php
            Session::flush('month');
            Session::put('month', 2);
            ?>
            <!-- Modal content-->
            <div class="modal-content">
                <form action="{{ route('panel.vip.payment') }}" method="post">
                    @csrf
                    <input type="hidden" value="2" name="plan">
                    <div>
                        <button type="submit">pay</button>
                    </div>
                </form>

                <button type="button" data-dismiss="modal">close</button>
            </div>

        </div>
    </div>

I want to clear the month session when any of the pay buttons are clicked and then the value for that button (1 or 2) set in the month session

How can I do this?

Thanks.

  • 写回答

1条回答 默认 最新

  • drymoeuka282427675 2019-08-12 06:13
    关注

    Button code :

    <div>
        <h3>1 month</h3>
        <button type="button" class="pay-btn-1" data-toggle="modal" data-target="#modal1">Pay this featur</button>
    </div>
    

    Modal code :

    <------ Modal 1------->
        <div id="modal1" class="modal fade" role="dialog">
            <div class="modal-dialog">
                <!-- Modal content-->
                <div class="modal-content">
                    <form action="{{ route('payment') }}" method="post">
                        @csrf
                        <input type="hidden" value="1" name="plan">
                        <div>
                            <button type="submit">pay</button>
                        </div>
                    </form>
    
                    <button type="button" data-dismiss="modal">close</button>
                </div>
    
            </div>
        </div>
    

    send ajax to PHP when clicked the button and removed session on the server-side.

    see below code :

    $('.pay-btn-1').click(function (e) {
                    e.preventDefault();
                    $.ajax({
                        type   : 'post',
                        url    : '/clear-session',
                        data   : {_token: "{{ csrf_token() }}"},
                        success: function (data) {
                            //
                        }
                    });
                });
    

    Now in the controller on clearSession method :

    public function clearSession(Request $request)
        {
    
            $request->session()->forget('Vip');
    
            return response()->json('ok', 200);
    
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器