[英]JavaScript Route with message Laravel Blade
I have following function which makes a redirect to my view home and pass the data to the success div. 我有以下功能,它可以重定向到我的视图主页,并将数据传递给成功div。 Here you can see the return line from that message... 在这里,您可以看到该消息的返回行...
return redirect('home')->with('success', 'Group is created!');
And this is the part in my view where the message is shown... 这是我认为显示消息的部分...
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@elseif (session('danger'))
<div class="alert alert-danger">
{{ session('danger') }}
</div>
@endif
Now I have this Java Script, where I want to have the message to the same part in my view like above. 现在,我有了这个Java脚本,我想在上面的视图中将消息传递到同一部分。 I get the redirect to the correct view home, but my message is not shown. 我将重定向到正确的视图主页,但是未显示我的消息。
success: function(data){
jQuery('.alert-danger').html('<p>'+data.successsuccess+'</p>');
window.location.href = "{{URL::to('/home')}}"
What I have to fix, that my message will be shown? 我必须解决的问题才能显示我的消息?
Thank you 谢谢
you should use Session::flash('message', 'This is a message!');
您应该使用Session::flash('message', 'This is a message!');
and don't forget to add use Session;
并且不要忘记添加use Session;
on your controller. 在您的控制器上。
then you can display it like this : 然后您可以像这样显示它:
@if (Session::has('message'))
<li>{!! session('message') !!}</li>
@endif
Try to use this instead: 尝试改用以下方法:
@if (session()->has('success'))
<div class="alert alert-success">
{{ session()->get('success') }}
</div>
@elseif (session()->has('danger'))
<div class="alert alert-danger">
{{ session()->get('danger') }}
</div>
@endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.