[英]Console.log does not show result based on variable value
I'm using Laravel 5.8 and in this project, I wanted to show some results in Javascript based on the variable which is sent to View.我正在使用 Laravel 5.8,在这个项目中,我想根据发送到 View 的变量在 Javascript 中显示一些结果。
So at the Controller, I have added this:所以在控制器中,我添加了这个:
$title = "";
if($popup->showtitle == 1){
$title = $popup->title;
}
return view("frontend.home")->with('title',$title);
Then at the view:然后在视图:
<script>
var title = JSON.parse("{{ json_encode($title) }}");
if(!title){
console.log(1);
}else{
console.log(2);
}
</script>
So basically, if title
does not have any value, it should be showing 1 at the Console bar, otherwise 2 must be appears.所以基本上,如果title
没有任何值,它应该在控制台栏显示1 ,否则必须显示2 。
But the problem is, it does not show anything at all!但问题是,它根本没有显示任何东西!
So what's going wrong out there?那么外面有什么问题呢? How can I properly get the result based on this variable value?我怎样才能根据这个变量值正确地得到结果?
in controller在控制器中
$title = "your title";
return view('rontend.home')->with([
'title' => $title,
]);
in blade在刀片
<script>
$(document).ready(function() {
var title = {!! json_encode($title) !!};
console.log(title);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.