Javascript Toastr将Laravel会话变量用作警报消息
我想从Javascript Toastr将Laravel会话变量用作警报消息,javascript,twitter-bootstrap,laravel,laravel-5,toastr,Javascript,Twitter Bootstrap,Laravel,Laravel 5,Toastr,我想从Bootstrap警报切换到Toastr警报。我目前的工作设置是: @if (Session::has('flash_notification.message')) <div class="alert alert-{{ Session::get('flash_notification.level') }}"> <button type="button" class="close" data-dismiss="alert"
Bootstrap
警报切换到Toastr
警报。我目前的工作设置是:
@if (Session::has('flash_notification.message'))
<div class="alert alert-{{ Session::get('flash_notification.level') }}">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
{{ Session::get('flash_notification.message') }}
</div>
@endif
但是,我想使用Laravel的会话变量来包含不同的消息和警告框:
@if (Session::has('flash_notification.message'))
<script>
$(document).ready(function() {
toastr.options.timeOut = 4000;
toastr.{{ Session::get('flash_notification.level') }}('{{ Session::get('flash_notification.message) }}');
});
</script>
@endif
@if(会话::has('flash_notification.message'))
$(文档).ready(函数(){
toastr.options.timeOut=4000;
toastr.{{Session::get('flash_notification.level')}}({{Session::get('flash_notification.message)}}});
});
@恩迪夫
我遇到了各种各样的错误,比如
意想不到的错误代码>。任何帮助都将不胜感激。非常感谢。由于您使用的是刀片模板,因此可以使用{{var/function()}
输出变量/函数的内容。如果您想要未扫描的输出,可以使用{!!var/function()!!}
因此,您的问题的解决方案是,您需要用{{}
标记包围php代码:
@if (Session::has('flash_notification.message'))
<script>
$(document).ready(function() {
toastr.{{ Session::get('flash_notification.level') }}
('{{ Session::get('flash_notification.message') }}');
});
</script>
@endif
@if(会话::has('flash_notification.message'))
$(文档).ready(函数(){
toastr.{{Session::get('flash_notification.level')}
({{Session::get('flash_notification.message')}});
});
@恩迪夫
谢谢您的回复。不幸的是,它返回的错误出乎意料代码>因为它在我的template.blade.php中,所以错误消息非常糟糕-97A837778D68883DB99BFDF8C10C794第66行中的FatalErrorException:语法错误,意外“;”代码>。第66行是:toastr.{{Session::get('flash_notification.level')}}({{Session::get('flash_notification.message)}})
Session::get('flash\u notification.message)
-您缺少flash\u notification.message之后的第二个
。非常正确!我自己也注意到了,谢谢。我现在就去检查一下。它看起来都是正确的,但是现在错误是:uncaughtreferenceerror:$未定义
。jQuery在页脚中被调用,但是document.ready
应该停止此错误吗?
@if (Session::has('flash_notification.message'))
<script>
$(document).ready(function() {
toastr.{{ Session::get('flash_notification.level') }}
('{{ Session::get('flash_notification.message') }}');
});
</script>
@endif