烤面包机没有出现在Laravel 5.4中

时间:2018-08-12 14:41:52

标签: jquery laravel laravel-5 laravel-5.4

我尝试使用Toast通知,我认为我已经包括了所有内容。可以在操作后生成的页面源上看到它,但是它没有在页面上显示通知。

包括:

def PaymentView(request):

    user_membership = get_user_membership(request)

    selected_membership = get_selected_membership(request)

    publishKey = settings.STRIPE_PUBLISHABLE_KEY

    if request.method == "POST":
        try:
            token = request.POST['stripeToken']
            subscription = stripe.Subscription.create(
              customer=user_membership.stripe_customer_id,# id on User Membership Model
              items=[
                {
                  "plan": selected_membership.stripe_plan_id,
                },
              ],
              source=token # 4242424242424242
            )

            return redirect(reverse('memberships:update-transactions',
                kwargs={
                    'subscription_id': subscription.id
                }))

        except stripe.error.CardError as e:
            messages.info(request, "Your card has been declined")

    context = {
        'publishKey': publishKey,
        'selected_membership': selected_membership
    }

    return render(request, "path/templategoeshere.html", context)

通话:

<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>

控制器:

<script>
    @if(Session::has('success'))
        toastr.success("{{ Session::get('success') }}")
    @endif
</script>

下图显示代码已成功通过:

code on page source

2 个答案:

答案 0 :(得分:0)

我最近有这个问题。为了解决这个问题,我确保执行以下操作:

(您的情况可能是第4点)

1)在布局文件中链接toastr.csstoastr.js

<link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet">
<script src="{{ asset('js/toastr.min.js') }}"></script>

2)不要在标记中使用defer属性

<script src="{{ asset('js/toastr.min.js') }}" defer></script>

应该是:

<script src="{{ asset('js/toastr.min.js') }}"></script>

3)导入jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

4)在敬酒之前加载jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="{{ asset('js/toastr.min.js') }}"></script>

5)确保拼写,functions等正确无误

答案 1 :(得分:0)

我只是确保将脚本加载到代码底部,紧接在标记之前,从而解决了我的问题。 `

<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="{{ asset('js/app.js') }}" ></script>
<script src="{{ asset('js/toastr.min.js') }}" ></script>
<script>
    @if(Session::has('success'))

    toastr.success("{{ Session::get('success')}}")
    @endif

    @if(Session::has('info'))

    toastr.info("{{ Session::get('info')}}")
    @endif
</script>

</body>
</html>`

最初我已将其放置在标签内